HTML and CSS Reference
In-Depth Information
The general rule when it comes to choosing between post and get is that if the form will
change any data on the server, you should use post . If the form is used to retrieve infor-
mation, using get is fine. For example, suppose that you're writing a message board pro-
gram. The registration form for new users and the form used to publish messages should
use the post method. If you have a form that enables the user to show all the posts
entered on a certain date, it could use the get method.
One other less frequently used attribute of the <form> tag is enctype . It defines how
form data is encoded when it's sent to the server. The default is application/x-www-
form-urlencoded . The only time you ever need to use enctype is when your form
includes a file upload field (which I discuss a bit later). In that case, you need to specify
that the enctype is multipart/form-data . Otherwise, it's fine to leave it out.
That about does it for the < form > tag, but you've really only just begun. The <form> tag
alone is just a container for the input fields that are used to gather data from users. It just
indicates where the data should go and how it should be packaged. To actually gather
information, you're going to need items called form controls.
Using the <label> Tag
Whenever you enter text that describes a form field, you should use the <label> tag, and
use the for attribute to tie it to the control it labels. To create a label, begin with the
opening label tag and then enter the for attribute. The value for this attribute, when pre-
sent, must match the id or name attribute for the control it labels. Next, enter text that
will serve as the label and then close the element with the end label tag, as in the fol-
lowing:
Input
<label for=“control4”> Who is your favorite NFL Quarterback? </label>
<input type=“text” name=“favqb” id=“control4” />
Figure 11.4 shows this text control with a label assigned to it.
 
 
Search WWH ::




Custom Search