Forms &
Common Gateway Interface (CGI) Scripts
Forms are HTML tags used to create data entry panels through which the Web visitor can supply information. This information is then submitted to a script on a Web server for processing.
The layout of a Web page can be formatted using forms:
- to coordinate and manage input of data or text
- to choose from items in a menu list or
- to select items by clicking on radio buttons or checkboxes.
Forms
<FORM. . . > Begin the entire form with this tag. </FORM> End the entire form with this tag.
<FORM Attributes >
ACTION="URL" URL address of the script to process data from the form. METHOD=get | post selects one of two possible methods of transmitting data from the form to a CGI script located on the server get appends the information entered in the form to the ACTION="URL" as an environmental variable QUERY_STRING post sends the information entered in the form as a body of data available as stdin, while the environmental variable CONTENT_LENGTH is set equal to the data length.
Example:
<FORM ACTION="http://www.server.com/cgi-bin/script.pl"
METHOD=POST>
Form Elements
Inside of the FORM tag, at least one of the following is required to define the form input fields:
<INPUT TYPE="attribute">
<INPUT TYPE=" attributes">
All attributes:
TYPE= "attribute" TEXT default, for text input PASSWORD to convert input to *s as hidden input CHECKBOX to present a checkable box before input RADIO to present a radio button before input; only one choice will be possible SUBMIT to display a button, labeled SUBMIT to transmit form input to the server RESET to display a button, labeled RESET to return form input to defaults HIDDEN to transmit hidden information to the server IMAGE to substitute a SRC=graphic for TYPE="SUBMIT" FILE to submit a file as input to the script on the server RANGE SCRIBBLE JOT
- FORM data is a stream of URL encoded name=value pairs separated by the & character.
- NAME="variable" - assigns a name to the input data; the symbolic name of the field as submitted to the server script; required except for TYPE=SUBMIT | RESET
- VALUE="value" - the value may be assigned as a default or assigned when the information is entered in the form.
- ALIGN=top | middle | bottom | left | right
- ERROR="err message" - text to be displayed if the entered value is invalid.
<INPUT TYPE="TEXT" | "PASSWORD"> only:
- SIZE="n" - where n is physical size of the displayed input field in characters or characters, rows.
- MAXLENGTH="n" - where n is the maximum number of characters accepted as input.
<INPUT TYPE="CHECKBOX" | "RADIO"> only:
- CHECKED - the checkbox is set as checked initially
<INPUT TYPE="HIDDEN"> only:
- VALUE="value" - default value to be sent to script on the server, such as e-mail address
<INPUT TYPE="SUBMIT | RESET"> only:
- VALUE="value" - text to be displayed on the face of the buttons
<INPUT TYPE="IMAGE"> only:
- SRC="URL.gif" - defines the graphic to be used instead of the SUBMIT button
<INPUT TYPE="RANGE"> only:
- MIN="n"
- MAX="n"
<SELECT. . . >
</SELECT> - defines a menu of drop-down or selectable inputs:
Inside the SELECT tags, one or more OPTION element will be included:
- NAME="variable" - the symbolic name of the field as submitted to the server script
- SIZE="n" - the number of OPTION elements
- MULTIPLE - if more than one possile OPTION may be selected
- ALIGN=top | middle | bottom | left | right - alignment
- <OPTION displayed text> - selectable optional elements
- SELECTED - default value of the OPTION if no other input provided
<TEXTAREA . . >
</TEXTAREA> - used instead of INPUT for freeform text input
- NAME="variable" - the symbolic name of the field as submitted to the server script
- ROWS="n" - the number of rows of text
- COLS="n" - the number of column in characters
- WRAP=off | soft - controls word wrapping within the TEXTAREA
- ALIGN=top | middle | bottom | left | right - alignment
- ERROR="err message" - text to be displayed if the entered value is invalid.
Examples of forms:
- Simple text entry form.
- Multiple line text forms, no defaults
- Password entry, without defaults.
- Radio buttons - single choice.
- Checkboxes with default and reset
- Hidden values and a graphic for SUBMIT
- Menus with SELECT and OPTION
- Freeform entry using TEXTAREA
- Form with an Image
- Simple form example
Common Gateway Interface (CGI)
The "common gateway interface" is the standard to which software is written so that browsers can exchange information or communicate with programs or scripts located on servers. The exchange of information results in one form of interactivity between client and host.
CGI programs or scripts can be written using:
Programs: COBOL, C++, Pascal languages which are compiled into machine code Interpreters: BASIC, Visual BASIC higher languages which are interpreted at the time the program is run Scripts: PERL, UNIX shell script, AppleScript languages which are read and run one line at a time. CGI scripts reside in a special subdirectory on the Web server reserved for executable files (often cgi-bin) because they actually run on the server, rather than the browser-client side.
CGI scripts can be written as Server Side Includes (SSIs) which start immediately when a Web page is loaded by the browser. Or they could be activated from within a <FORM> tag in an HTML file. Or they can be written as executable scripts which start when a link to that program is clicked.
Since CGI scripts run on the server, there may be security loopholes. Thus, some ISPs do not allow for custom CGI scripts on personal Web sites. CSPs and ISPs like America Online, CompuServe, and Earthlink only allow CGI scripts on commercial Web sites.
Some Web hosting sites provide a standard set of "canned CGI scripts" for use by their personal Web site owners. Examples of these include:Other popular forms may use custom CGI scripts:
- imagemaps
- mailto
- mailto_silent
- appendto
- counter
- guestbook
- password access
- send a cookie
- registration form
CGI Environmental Variables
Environmental variables are set or defined when the server executes a gateway program and passes data as an argument or value to the CGI script, much like the way programming variables can be set and passed between programs.There are about 20 environmental variables, used to describe the hardware or software environment in which the script is operating. The major ones include:
- AUTH_TYPE
- CONTENT_LENGTH
- CONTENT_TYPE
- GATEWAY_INTERFACE
- HTTP_ACCEPT
- HTTP_REFERER
- HTTP_USER_AGENT
- PATH_INFO
- PATH_TRANSLATED
- QUERY_STRING
- REMOTE_ADDR
- REMOTE_HOST
- REMOTE_IDENT
- REMOTE_USER
- REQUEST_METHOD
- SCRIPT_NAME
- SERVER_NAME
- SERVER_PROTOCOL
- SERVER_PORT
- SERVER_SOFTWARE
Technology Place
2807 Highland Avenue - Suite 5
Santa Monica, CA 90405
(310) 396-9863
E-mail: techplace@earthlink.net
© Copyright 1996, 1997 by Technology Place. All rights reserved.