The Basic Form (<form>)
The <form>
tag, which is used to designate a
form, contains the information necessary for interacting with the CGI
program on the server. A form is made up of a number of control
elements (text-entry fields, buttons, etc.) used for entering
information. When the user has completed the form and presses the
“submit” button, the entered data is passed to the CGI
program specified by the action
attribute.
You can have several forms within a single document, but they cannot be nested and you must be careful they do not overlap.
Figure 12.1 shows a very simple form and its
<form>
tag.
Figure 12-1. A simple form
The action attribute
The
action
attribute in the
<form>
tag provides the URL of the program
to be used for processing the form. By convention, CGI programs are
usually kept in a directory called cgi-bin. In
the example in Figure 12.1, the form information is
going to a Perl script called mailform.pl
which resides in the cgi-bin
directory of the
current server.
The method attribute
The method
attribute
specifies one of two ways, either
get
or post
, in which the
information from the form can be transmitted to the server. Form
information is transferred in a series of
name=value
pairs, separated by the
ampersand (&
)
character.
Let’s take into consideration a simple form with two fields: one for entering a name, and the other for entering a nickname. If a user enters ...
Get Web Design in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.