Up to now, all the (X)HTML you have learned has helped you communicate your ideas with your visitors. In this chapter, you'll learn how to create forms which enable your visitors to communicate with you.
There are two basic parts of a form: the collection of fields, labels, and buttons that the visitor sees on a page and hopefully fills out, and the processing script that takes that information and converts it into a format that you can read or tally.
Constructing a form's fields and buttons (pages 254276) is straightforward and similar to creating any other part of the Web page. You can create text boxes, special password boxes, radio buttons, checkboxes, drop-down menus, larger text areas, and even clickable images. You will give each element a name that will serve as a label to identify the data once it is processed. I'll also show you how to format forms with CSS.
Processing the data from a form is only slightly more complicated. While in earlier editions I recommended using Perl to write CGI scripts, I now heartily recommend using PHP. It is easy and straightforward and perfectly suited to making Web pages interactive.
While both PHP and Perl are beyond the scope of this book, and even explaining how to use existing scripts stretches the limits a bit, I have provided some ready-made scripts to help you get started (see pages 256 and 258).
|Creating a Form|
|Sending Form Data via Email|
|Organizing the Form Elements|
|Creating Text Boxes|
|Creating Password Boxes|
|Formally Labeling Form Parts|
|Creating Radio Buttons|
|Creating Larger Text Areas|
|Allowing Visitors to Upload Files|
|Creating Hidden Fields|
|Creating the Submit Button|
|Resetting the Form|
|Using an Image to Submit Data|
|Setting the Tab Order in a Form|
|Adding Keyboard Shortcuts|
|Disabling Form Elements|
|Keeping Elements from Being Changed|