If you are beginning to suspect a good-news/bad-news scenario on the way, you are correct. Anyone can create a FORM. Forms consist of additional HTML tags that allow the reader to enter information. That is the good news. Now for the bad news. Where does that information the user entered on the FORM go? It needs to go to a program. A program (usually) living on a server. Yes, you may be able to use client side Java or ActiveX but the bottom line is the reader has information you want, you want to capture and store that information somewhere. That somewhere is usually a datafile (or database) living on a server.
The program that reside on the server are refereed to as CGI (Common Gateway Interface ) programs. There in lies the rub. The CGI is on the server which means it is using the servers CPU (everyone all at once ... Central Processing Unit). The CGI is also is using the servers disk space. A poorly (or in some instances excellent) CGI programs could (in random order):
On the client side, there are several HTML tags that can be used to capture data.
Three of the more common types of form entry tags (also known as fields) are:
NOTE: You can supply default values for the TYPE= input by specifying a VALUE= or for the TEXTAREA by placing text between the the <TEXTAREA> and </TEXTAREA>.The default along with the entered text is sent to the CGI program.
The CGI program need only concern itself with NAME and the VALUE pair and is independent of the type of tag (INPUT, TEXTAREA, etc) used.
Other types of FORM tags are:
The FORM at the top of this page is a full functioning form. The information is sent to a CGI program called rgecho9.pl
. The FORM tag for that form is:
<FORM ACTION="http://www.polar.sunynassau.edu/~ricky/cgi-bin/rgecho9.pl" METHOD="post">
The ACTION= must meet the typical absolute or relative URL rules.<input type="text" name="enter_name">
<INPUT TYPE="radio" NAME="fun" VALUE="YES">
<INPUT TYPE="radio" NAME="fun" VALUE="NO">
There are two radio buttons, one has a VALUE="YES" and the other has a VALUE="NO". Both have the same NAME so only one may be marked.<TEXTAREA NAME="feedback" ROWS=3 COLS=10> </TEXTAREA>
The ROWS= and COLS= options just state the box size and does not restrict to the actual number of characters entered.<INPUT TYPE="checkbox" NAME="more">
Note the default value that the CGI has for this field.<INPUT TYPE="password" NAME="secret_shhhhhhh">
When information is typed in this field, the actual characters are not displayed.<INPUT TYPE="submit" NAME="Submit" VALUE="Submit">
The RESET button does NOT send information to the CGI program.
All FORM tags must be enclosed in <FORM> and </FORM> pair. On the <FORM> tag, there are two important options.
http://www.polar.sunynassau.edu/~ricky/cgi-bin/rgecho9.pl?style=command+line+info&fun=yes
You can create a link to a CGI as you would any other web page:
Click HERE
The above source is:
<A HREF= "http://www.polar.sunynassau.edu/~ricky/cgi-bin/rgecho9.pl?style=from+a+HREF&fun=yes" >
The ?style=from+a+HREF&fun=yes
is known as a Non-Parsed Header (NPH) in CGI terminology. The CGI programmer must either write code or obtain code from somewhere to convert the NPH into the human-readable format as displayed by the CGI. (After invoking the CGI, scroll down take note of the QUERY_STRING enviornment variable.)
Some say the proper way to do FORMs is to have the same CGI program produce both the FORM and obtain the results. This can accomplished by looking at the request method. If the request method is GET (invoked either from a browser command line or from a <A HREF in an HTML page, then the program displays the FORM. When displaying the FORM, it prints the <FORM ACTION="its own url" METHOD="POST"> so that when the SUBMIT is hit, the CGI knows it has data since the method is POST.
There is other information that is passed in the environment block. This contains information concerning the server. It is in this block where you find the REQUEST_METHOD (POST or GET) and the SCRIPT_NAME to create the ACTION= for the <FORM> tag.
One of the convenitions a CGI program must obey is that an output of what is called a CONTENT HEADER. This content header (also known as a MIME type) defines to the browser what type of output is comming. The most common is Content-type: text/html
. This states that output of the CGI program is to be treated as HTML code.
There are many MIME types, some common ones are:
A long time ago (a few months in web life) one was able to create a FORM and have the information e-mailed to a user. This was accomplished by setting the ACTION= of the <FORM> tag to be mailto:someone@somewhere.site
. This will still work provided that the reader is using Netscape browser with the default Mozilla e-mail utility. The problem is that whenever on either replaces Mozilla with other mail software or is using Internet Explorer is that the mail protion does not know how to handle the NPH sent to it by the browser. This is the same problem as creating a mailto: URL.
In short, your CGI program need only concern itself (for the most part) with NAME and the VALUE and is independent of the type of TAG used.
CMP 217 students should also see http://www.ncc.edu/~glassr/assign/cginotes.htm