Forms and CGI Scripts
Introduction
What follows is the web-based version of a lecture I gave for CMSC 498P, Advanced
Authoring for the World-Wide Web, on February 13, 1996. The purpose of the
lecture was to "refresh" (read: teach) the students how to use forms in HTML and how
to handle them via server-side CGI scripts. The progress of the lecture is outlined
below.
Revisions
These documents were updated on January 22, 1998 in order to clean up some of the HTML
code and to port the CGI scripts from C to Perl. The C source code remains available
as is the Perl source code.
Outline
- Introduction
- Forms are the means through which a user may enter, and then submit, data into
a web browser. The data may then be submitted to the web server via the World-Wide Web.
- CGI scripts are programs that reside and execute on the web server and provide
the means by which a form's submitted data is parsed, evaluated, and reacted upon.
- We will be reviewing forms as defined by the
HTML 2.0 specification,
the expired HTML 3.0
draft, CGI scripts as pertain to handling form data, and miscellaneous information
related to these subjects.
- A brief overview of an HTML tag's structure is provided.
- Forms in HTML 2.0
- The FORM element announces the beginning of the form data set
- The INPUT element represents a user input field and comes in 8 varieties
- TEXT - A single line text entry field
- PASSWORD - The same as a TEXT field but the values are obscured
- HIDDEN - A hidden field that carries pre-determined information
- CHECKBOX - A field that allows a yes/no (boolean) entry
- RADIO - Radio buttons allow a one-of-many choice
- RESET - Usually a button that resets the form fields to thier defaults
- SUBMIT - Usually a button tht instructs the browser to submit the form
- IMAGE - Allows an image to be used in place of a submit button
- The SELECT element allows the user to select from a list of options
- The TEXTAREA element represents a multiline text input field
- A working HTML 2.0 sample form
- Forms in HTML 3.0
- Additions to the HTML 2.0 spec
- Three new INPUT types
- RANGE - Allows the suthor to define a range
- SCRIBBLE - Allows the user to "scribble" on top of a predefined image
- FILE - Allows the user to upload a file
- Form handling script
- Form input and URL encoding
- The CERN form parsing script
- The NCSA form parsing scripts
- Form output - use the sample form from item III which uses the NCSA method