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:

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 Elements


Inside of the FORM tag, at least one of the following is required to define the form input fields:

<INPUT TYPE="attribute">

<SELECT. . . >
</SELECT>

<TEXTAREA . . . >
</TEXTAREA>




<INPUT TYPE=" attributes">
TYPE="attribute"
TEXT default, for text input
PASSWORDto convert input to *s as hidden input
CHECKBOXto present a checkable box before input
RADIOto present a radio button before input; only one choice will be possible
SUBMITto display a button, labeled SUBMIT to transmit form input to the server
RESETto display a button, labeled RESET to return form input to defaults
HIDDENto transmit hidden information to the server
IMAGEto substitute a SRC=graphic for TYPE="SUBMIT"
FILEto submit a file as input to the script on the server
RANGE
SCRIBBLE
JOT

All attributes:

<INPUT TYPE="TEXT" | "PASSWORD"> only:


<INPUT TYPE="CHECKBOX" | "RADIO"> only:


<INPUT TYPE="HIDDEN"> only:


<INPUT TYPE="SUBMIT | RESET"> only:


<INPUT TYPE="IMAGE"> only:


<INPUT TYPE="RANGE"> only:



<SELECT. . . >
</SELECT> - defines a menu of drop-down or selectable inputs:
Inside the SELECT tags, one or more OPTION element will be included:


<TEXTAREA . . >
</TEXTAREA> - used instead of INPUT for freeform text input

Examples of forms:

  1. Simple text entry form.
  2. Multiple line text forms, no defaults
  3. Password entry, without defaults.
  4. Radio buttons - single choice.
  5. Checkboxes with default and reset
  6. Hidden values and a graphic for SUBMIT
  7. Menus with SELECT and OPTION
  8. Freeform entry using TEXTAREA
  9. Form with an Image
  10. 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++, Pascallanguages which are compiled into machine code
Interpreters:BASIC, Visual BASIChigher languages which are interpreted at the time the program is run
Scripts:PERL, UNIX shell script, AppleScriptlanguages 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:

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:


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.