Link to USGS home page
Internal USGS Access Only

CGI and Forms

What is CGI?
CGI is a description of how browsers can pass information to servers over the web, and how the web server can display results for a browser to see.
Forms and associated programs
The only way to process information from a form is through CGI. (or some other program interface, such as ASP); Information from fields in the form is set to variables that are passed to a GCI program.
Languages
CGI programs can be written in almost any language, including shell scripts, but the most common language for CGI programs is perl.
Result
A CGI program can either create html to be displayed, or send the user to a new location.

Forms

Forms gather information, which is associated with variables, and provide this information to a (CGI - Common Gateway Interface) program. All forms-specific tags must be within FORM tags:
<form method="get" action="url"> . . . </form>

Where url is a URL to a CGI program or a "mailto:":
<form method="post" action="mailto:registrar@usgs.gov"> . . . </form>
and the method is either "get" or "post". The default method is "get " and the default URL is the current document.

Form Methods

GET
Passes the form's input to the server in a variable called QUERY_STRING. Becomes part of the URL. Commonly used by search engines. Allows bookmarking. Ex: http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=lorna
POST
Passes the form's input to the server in an URL encoded stream. Must be used with the content from the form needs to be hidden. Most commonly used method for forms. Not possible to bookmark.

Note: Form information which is posted must be decoded. A perl script to provide this decoding is available.

slide 47


[up]
"Mastering a Web Site" online course
Created and maintained by Lorna Schmid and David Boldt.
http://water.usgs.gov/usgs/training/webmaster/forms-cgi.html    
Last modified: Wed Nov 12 17:24:58 EST 2003