Page 263 - Beginning PHP 5.3
P. 263
Chapter 9: Handling HTML Forms with PHP
Figure 9-1
How It Works
This XHTML Web page contains the most common types of form controls you’re likely to come across.
First, the form itself is created:
<form action=”” method=”get”>
Notice that the form is created with the get method. This means that the form field names and
values will be sent to the server in the URL. You learn more about the get and post methods
shortly. Meanwhile, the empty action attribute tells the browser to send the form back to the same
page (web_form.html). In a real-world form this attribute would contain the URL of the form
handler script.
Next, each of the form controls is created in turn. Most controls are given a name attribute, which is the
name of the field that stores the data, and a value attribute, which contains either the fixed field value
or, for fields that let the users enter their own value, the default field value. You can think of the field
names and field values as being similar to the keys and values of an associative array.
Most controls are also given an associated label element containing the field label. This text describes
the field to the users and prompts them to enter data into the field. Each label is associated with its
control using its for attribute, which matches the corresponding id attribute in the control element.
225
9/21/09 7:23:33 PM
c09.indd 225
c09.indd 225 9/21/09 7:23:33 PM