Workshop: Building an Entire Form

Now you’ve been introduced to all the fields that can be used in an HTML form. At this point, I’m going to talk about how you put these pieces together to create a usable form. Generally speaking, a form consists of more than just a group of fields—those fields need to be labeled, and often some explanation is required in order to help users understand what’s going on.

In this case, I’m going to create a simple survey form, of the kind one might fill out to get a free subscription to a trade magazine. The source code for the HTML form appears in Listing 5.1.

Listing 5.1. survey.html, A Sample Survey Form
 1: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 2: "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ...

Get Sams Teach Yourself CGI in 24 Hours, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.