09.06.2015 Views

learn_HTML

learn_HTML

learn_HTML

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>HTML</strong>5: Form Validation<br />

You have probably seen forms<br />

on the web that give users<br />

messages if the form control has<br />

not been filled in correctly; this is<br />

known as form validation.<br />

Traditionally, form validation<br />

has been performed using<br />

JavaScript (which is beyond the<br />

scope of this book). But <strong>HTML</strong>5<br />

is introducing validation and<br />

leaving the work to the browser.<br />

Validation helps ensure the<br />

user enters information in a<br />

form that the server will be able<br />

to understand when the form<br />

is submitted. Validating the<br />

contents of the form before it is<br />

sent to the server the helps:<br />

chapter-07/html5-form-validation.html<br />

<br />

Username:<br />

<br />

Password:<br />

<br />

<br />

<br />

<strong>HTML</strong><br />

Result<br />

●● Reduce the amount of work<br />

the server has to do<br />

●● Enables users to see if there<br />

are problems with the form<br />

faster than if validation were<br />

performed on the server.<br />

At the time of writing, only<br />

Chrome and Opera supported<br />

<strong>HTML</strong>5 validation, although other<br />

browsers are expected to follow.<br />

In order to support older browsers<br />

(that do not understand <strong>HTML</strong>5),<br />

web page authors are likely to<br />

continue using JavaScript to<br />

validate forms.<br />

An example of <strong>HTML</strong>5 form<br />

validation is the required<br />

attribute, which can be used on<br />

any form element that the user<br />

is expected to fill in. This <strong>HTML</strong>5<br />

attribute does not need a value,<br />

but in <strong>HTML</strong> 4 all attributes must<br />

have a value. So, some people give<br />

this attribute a value of required.<br />

165 FORMS

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!