
Go backward to 4.4 CGI Introduction to Perl Topic #2
Go up to 4 Major Topics
Go forward to 4.6 Cookies
4.5 Form Processing
This topic is to introduce
HTML forms. This is where the WWW gets a bit more interesting.
The client can finally provide some real data to the server.
The data from the user can be information about the user,
information about something wanted, or purchase information.
The possibilities are endless.
There are two primary ways for the CGI program to get the data,
"POST" & "GET".
POST sends the input through the the standard input to the CGI program while
GET uses the environment variable "QUERY_STRING
".
You can determine the type of request by looking at the
environment variable "REQUEST_METHOD
".
The details in handling the the character translations and different
form methods needs little attention. Use someone else's code to do it.
Look at the file common.pl
for some ideas, or just use it.
You may want to revise your last lab so that it can handle forms
using ether method.
- Read Chapter 4 of CGI Programming by Gundavaram
On the web at O'Reilly. Pages 51-85.
- Create a form, and point it at your
environment
program.
Look at the environment created by the HTTPD as provided to
your program when presented with a form.
- If you choose, modify the program to look at the standard
input
STDIN
if the request method is "POST".
- Construct an HTML form that has the following fields:
- Date (Month, Day, Year)
- Time (24 Hour time or 12 Hour and "AM" & "PM")
- Temperature (I think in Fahrenheit)
- Event "Radio Buttons" for the type of weather.
- Write a CGI Perl program that:
- Creates a data file if it doesn't exist.
- Saves the data from the form to the file.
Use the name of your script without the .pl with an .data.
If the file already has data in it, append the new
data to the file. Time stamp the entries in the file.
- Deals with race conditions by locking the file on write.
Critical section problems related to reading the file are also
possible,
but in this case, not worth worrying about.
- Processes the data in name.data and displays the data in
a table.
- Compute the average of the temperature fields. Include this
information on your page.
- Count the occurrence of each event and display
this information in a second table.
- Incorporates the data entry form, so the user can add additional data.
(So you won't need a separate form when you are done, you might
need it to get it to work initially.)
If you have a project in mind with about the same complexity using
forms please talk to me before starting this one. It never hurts to do
something that is actually useful to someone.
Turn in your report marked as follows:
- your name
- Louis Taber CSC266 Topic: 4.5: Form processing.
- A printout of your Perl CGI program.
- A printout of your processed data report from a web browser.
This should include your form for inputting data.
Instructor: ltaber@pima.edu** My new Home on phRed** The Pima College Site** The Mad Dr. G.'s home page on phred.
