9.1. Understanding Forms

HTML forms allow users to interact with Web documents by providing GUI controls for data entry. The HTML side of forms simply collects the data. A separate handler, usually a script of some sort, is used to do something useful with the data. A typical interaction with an HTML form resembles that shown in Figure 9-1.

Figure 9-1. Figure 9-1

The steps in the flow are as follows:

  1. The Web server sends the HTML document (containing the form) to the user agent.

  2. The user uses the form's GUI controls to enter data and submits the completed form.

  3. The form is submitted to a specified server (typically the same server that delivered the form document) to be passed to a handler.

  4. The server passes the data stream to a specified handler, which uses the data in a prescribed method.

A sample form, using the various form fields, is shown in the following code and rendered in a user agent in Figure 9-2.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>A Simple Form</title> </head> <body> <p> <form action="formdata.cgi" method="post"> <table cellspacing="20"> <tr><td> <!-- Text boxes --> <p><label for="fname">First Name: </label> <input type="text" name="fname" id="fname" size="20"><br> <label for="lname">Last Name: </label> <input type="text" name="lname" id="lname" size="20"> </p> <!-- Text ...

Get Web Standards Programmer's Reference: HTML, CSS, JavaScript®, Perl, Python®, and PHP now with O’Reilly online learning.

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