+++ title = "Inline Validation" template = "demo.html" +++ This example shows how to do inline field validation, in this case of an email address. To do this we need to create a form with an input that `POST`s back to the server with the value to be validated and updates the DOM with the validation results. We start with this form: ```html

Signup Form

``` Note that the first div in the form has set itself as the target of the request and specified the `outerHTML` swap strategy, so it will be replaced entirely by the response. The input then specifies that it will `POST` to `/contact/email` for validation, when the `changed` event occurs (this is the default for inputs). It also specifies an indicator for the request. When a request occurs, it will return a partial to replace the outer div. It might look like this: ```html
That email is already taken. Please enter another email.
``` Note that this div is annotated with the `error` class and includes an error message element. This form can be lightly styled with this CSS: ```css .error-message { color:red; } .error input { box-shadow: 0 0 3px #CC0000; } .valid input { box-shadow: 0 0 3px #36cc00; } ``` To give better visual feedback. Below is a working demo of this example. The only email that will be accepted is `test@test.com`. {{ demoenv() }}