Forms bring life and interactivity to
your documents, allowing interaction with the user, customized pages
based on individual preferences, and form the basis of every
interactive site.
Forms combine both conventional HTML
content and special elements to create pages users can manipulate.
As you might expect, every form begins with a <FORM>
tag. The <FORM>
tag serves three purposes: It alerts the browser that a form is to
be created, it identifies the server-side program that will process
the data collected by the form, and it defines the way that the data
will be passed to the server for processing.
A classic <FORM>
tag looks something like this:
<FORM ACTION="http://server.com/cgi-bin/script" METHOD="post">
...
</FORM>
When the user submits the form for processing, the
browser collects the values from the form elements and forwards them
using the post
method to server.com
for processing by /cgi-bin/script.
The script should produce some HTML as a result, and the browser
will display this HTML as a fresh document after the form is
processed.
For a form to work correctly, the ACTION
attribute must provide the URL of an executable program on the
server. You can't supply a document for the action, and you can only
supply a program that the server knows about and can run.
Scripts are stored by the server assigned in the path directory: cgi-bin.
The program must be able to read its parameters
using one of the two methods
available: post or get.
Each method has its advantages and disadvantages.
The post
method packages the form data and sends it to the server in a
second, separate transmission after the server-side program has been
contacted. It is best used for large amounts of data or forms with
many elements. It is also required for certain kinds of form data,
notably file transfers. On the down side, writing server-side
program to read post
data is slightly more difficult. In addition, post-style
applications can only be invoked via a form.
The get
method tacks the form parameters onto the URL when it invokes the
form program on the server. The server pulls them apart and passes
them to the program, usually as part of its command line. Thus, get-style
applications are easier to write, but only work well with a small
number of form parameters. You can invoke these programs without
using a form, however, by creating a URL that references the program
and appends the parameters as part of the URL.
The one you choose depends on your programming
skills, server, and the form you create.
Forms without servers
When forms first came on the scene, their only
purpose was to collect data and pass it to a server for processing.
As better client-side processing became available through Java and
JavaScript, some forms were used to collect data for these
client-side programs. In these cases, you need not specify an ACTION
or a METHOD;
the processing is handled by scripts and code embedded in your
document.
The purposes: you need not provide an action,
a METHOD,
or a client-side application. Simply using the <FORM>
tag without any attributes is enough to cause the browser to create
the elements within the form.
<< BACK