Forms
Videos
Form Tutorial
Links
- http://zaphod.cs.umd.edu/cgi-bin/reflector.cgi - use this to test your forms
Notes
Forms let users send us information
through web pages. If you have ever shopped online or filled out an
information request, you have used this feature.
To start a form is fairly simple. You use the FORM tag and it's corresponding end tag.
You need to include two attributes to make the form actually send
information. The first is the method attribute which describes how the
data is encoded. There are two options: post and get. For our purposes,
their function is essentially the same. I will use post in most of my
examples. The second attribute is the action which describes where and
how to transmit the data from the web page. This is set equal to a program that is on
a server that can process the form information. This is often called a CGI
(Common Gateway Interface) file. I
have written a CGI for you to use that nicely displays the contents of your form
that were submitted. To use this CGI, you set your action attribute equal to the URL of the
file:
Once we have that setup, we just need to add the data fields for the
user to fill out. Within a set of form tags, you can include any regular
HTML, plus the input fields of a form.
For any type of form widget, you need to include the name attribute. When
information is transmitted to you, it is sent in name value pairs. If
you see something like this:
You would receive something like city="Arlington, VA". You need to be able to identify the information coming across,
and the "name" attribute allows you to do that. There is also a value
attribute which lets you specify a default value for a field (like
Arlington, VA above) or to specify the actual value to be transmitted
for something like a checkbox where the user does not type in
information. We will see examples of these attributes used after looking
at the different types of input available.
After you have started the form tag, there are a variety of input tags you
can use. The tag structure is <input .... followed by
attributes. The type attribute controls what type of widget appears. This table
lists the different types and shows examples of each.