Chapter 5. Forms

Almost every time you want to collect information from a visitor to your site, you need to use a form. Some forms are quite complex, such as those that allow you to book plane tickets or purchase insurance online. Others are quite simple, such as the search box on the homepage of Google.

Many of the forms you will fill out online bear a strong resemblance to paper forms you have to fill out. On paper, forms are made up of areas to enter text, boxes to check (or tick), options to choose from, and so on. Similarly, on the Web you can create a form by combining what are known as form controls, such as textboxes (to enter text into), checkboxes (to place a cross in), select boxes and radio buttons (to choose from different options), and so on. In this chapter, you learn how each of these different types of controls can be combined into a form.

In this chapter then, you'll learn the following:

  • How to create a form using the <form> element

  • The different types of form controls you can use to make a form — such as text input boxes, radio buttons, select boxes, and submit buttons

  • What happens to the data a user enters

  • How to make your forms accessible

  • How to structure the content of your forms

By the end of the chapter, you will be able to create all kinds of forms to collect information from visitors to your site.

XHTML is used only to present the form to the user; it does not allow you to say what happens with that data once it has been collected. To get a better idea of what happens ...

Get Beginning HTML, XHTML, CSS, and JavaScript® now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.