Notice! This document is currently in Archived status.
The content of this document may be incorrect or outdated.

Print this article Edit this article

Processing form data

A form provides a familiar way to collect data from the user. The Web server passes the form input to a script or program on your system called a gateway. The gateway can process the input however you choose. It may return customized HTML based on the user's input, log the input to a file, or email it to someone. For example, the ECN email-form uses a gateway program that allows you to create your own forms and have the input mailed to you or someone else.

Your CGI Interface

First you should become familiar with running CGI (common gateway interface) programs. For information on how to run CGI programs within ECN, read the How to Run CGI Programs Answer.

You will need to become familiar with cgi scripts because you will need a gateway program or script to process the input from your form.

Overview of Steps

  1. In your ~/public-web/ directory. Create/edit your .htaccess file to execute cgi and define a file extension that will tell web server to run the file as a cgi. For example:
    	Options ExecCGI
    AddType application/x-httpd-cgi .cgi

  2. Create a cgi script.

  3. In your html document, reference your cgi script.

The Form

This document will be a file in which you will insert HTML form tags to create your form.

To reference your CGI file, you must have a line like this in your form document:

	<form method ="POST" action="userform.cgi">
"userform.cgi" is the name of the script or program you created in step #2 above.

Your file userform.cgi is the program which handles the input of your form. Or it can be a shell script which contains a reference to another program which handles the input of your form. You can see this as in example in the How to create a form using ECN email-form

Conclusion

You must have the following in your ~/public-web/ directory or a subdirectory of your ~/public-web/ directory:

  1. A .htaccess file. This file must be world readable:
    	% chmod 744 .htaccess or

    % chmod o+r .htaccess

  2. A CGI program which will handle the input of your form. This program must be in mode 755:
    	% chmod 755 file.cgi or

    % chmod o+xr file.cgi
    This filename extension must be the same as the file extension defined in your .htaccess file. The file could be named file.cgi.

  3. The form itself, which is an HTML document. This file must be mode 755:
    	% chmod 755 file.html or

    % chmod 0+rx file.html

To View and Test Your Form

After you have followed the above steps and created a form, you can now view it and test it. To view the form file, which will be in your ~/public-web/ go to the URL:
	http://host.ecn.purdue.edu/~login/form.html
You do not need to put "public-web" in the URL. To test your form, just fill in the fields and send/submit it.

Additional Information

How to Run CGI Programs
How to Create a Form Using ECN email-form
Carlos' Forms Tutorial

Last Modified: Dec 19, 2016 11:12 am US/Eastern
Created: Mar 21, 2007 12:02 pm GMT-4 by admin
JumpURL: