23.05.2015 Views

Building the User Interface by Using HTML5: Organization ... - server

Building the User Interface by Using HTML5: Organization ... - server

Building the User Interface by Using HTML5: Organization ... - server

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Building</strong> <strong>the</strong> <strong>User</strong> <strong>Interface</strong> <strong>by</strong> <strong>Using</strong> <strong>HTML5</strong>: <strong>Organization</strong>, Input, and Validation | 73<br />

• To capture user comments after an article on a Web site<br />

• To select preferences on a Web page<br />

• To enter reservation information<br />

Many client applications use some kind of Web form to interact with <strong>the</strong> user.<br />

You use HTML input elements to build a form’s interface and ensure that information is collected<br />

from users consistently. Validation ensures that <strong>the</strong> entered information is in <strong>the</strong> correct format<br />

and usable before sending <strong>the</strong> data to <strong>the</strong> <strong>server</strong>. For example, if you enter “637 Park Street” into<br />

a Web address field, which is expecting something like “http://www.example.com”, validation will<br />

fail and prompt <strong>the</strong> user to correct <strong>the</strong> input. Validation also reduces <strong>the</strong> amount of spam and<br />

malicious content that can make its way to <strong>the</strong> <strong>server</strong> or <strong>the</strong> recipient of <strong>the</strong> form’s data.<br />

LICENSED PRODUCT NOT FOR RESALE<br />

Understanding Input and Forms<br />

TAKE NOTE<br />

*<br />

Check <strong>the</strong> functionality<br />

of any form you create<br />

in many different browsers<br />

during development.<br />

This ensures <strong>the</strong> elements<br />

and attributes you<br />

select work as expected<br />

or <strong>the</strong> fall-back<br />

method collects acceptable<br />

input.<br />

Table 3-4<br />

Form element attributes used<br />

in <strong>HTML5</strong><br />

Most Web forms, or at least many fields in most forms, require specifically formatted<br />

input. The new <strong>HTML5</strong> form and input attributes are intuitive, easy to use, and replace<br />

a lot of scripting that was required in HTML 4.01 and previous versions.<br />

Form input is <strong>the</strong> information a user enters into fields in a Web or client application form.<br />

(To keep things simple, we use <strong>the</strong> term “Web form” most of <strong>the</strong> time, but it applies to client<br />

application as well.) <strong>HTML5</strong> introduces several new form and input element attributes, such<br />

as url for entering a single Web address, email for a single email address or a list of email<br />

addresses, and search to prompt users to enter text <strong>the</strong>y want to search for. The new attributes<br />

make form development much easier than in <strong>the</strong> past. What used to take a lot of scripting<br />

can be accomplished <strong>by</strong> <strong>HTML5</strong> tags.<br />

On <strong>the</strong> flip side, many of <strong>the</strong> new attributes are not yet supported <strong>by</strong> all of <strong>the</strong> major browsers.<br />

However, if you use a new element or attribute that isn’t yet supported, <strong>the</strong> browser “falls<br />

back” to an alternate display, a different form of input, or what have you.<br />

<strong>HTML5</strong> introduces two new attributes for <strong>the</strong> form element—autocomplete and novalidate.<br />

All attributes for <strong>the</strong> form element are listed in Table 3-4, with <strong>the</strong> new attributes indicated<br />

with a double asterisk.<br />

ATTRIBUTE VALUE DESCRIPTION<br />

accept-charset character_set Specifies a set of character encodings <strong>the</strong><br />

<strong>server</strong> accepts<br />

action URL Specifies <strong>the</strong> Web address to which form<br />

data is sent<br />

autocomplete** on Specifies whe<strong>the</strong>r autocomplete is on or off<br />

off<br />

in a form or input field; can be “on” for<br />

specific input fields and “off” for <strong>the</strong> form,<br />

or vice versa<br />

enctype application/x-www- Specifies <strong>the</strong> encoding type for form data<br />

form-urlencoded when submitting <strong>the</strong> data to a <strong>server</strong>;<br />

multipart/<br />

used only for method="post"<br />

form-data<br />

text/plain<br />

(continued)

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

Saved successfully!

Ooh no, something went wrong!