Homework 6

Due: WEDNESDAY, February 27, 11:59:59 pm

1. Server-side Validation (50 pts.)

Create a cgi script that validates form data

The user should be presented with an HTML form page to enter name and address:


The cgi script must make sure that every data field contains data and that the zip code contains five digits. It must also change the state abbreviations silently to upper case. If a field is empty or the zip code doesn't contain five digits, the form must be returned to the user for correction, including the data that the user provided. If the data is correct, the user must receive a message stating that the data was accepted.

Note: The Perl function to turn a string into upper case is uc( string ). To get the length of a string, use length( string ). For testing a string for character classes with the matching operator ( m/  / ), see Johnson, Elements of Programming with Perl, Chapter 10.2.2, p. 191.

The initial page may be a static HTML page; the correction page and the 'accepted' page must be created by the cgi-script.

2. Hidden Fields (25 pts.)

Create a cgi script that uses a hidden field to pass user-supplied data across html pages.

The user should be presented with an HTML form page with a field to enter a name and submit button. On submit, another form page must be called up to enter more data of your choice. A text input field and a submit button would suffice. This form page must contain the name entered into the previous form as a hidden field. The submit button shall call up a third page that will display the data entered in both form pages, including the name.
The first page may be a static HTML page, the others must be created by cgi-script(s).

3. Cookies (25 pts.)

Create a cgi script that uses Perl cgi.pm cookies to pass user-supplied data across html pages

Implement assignment 2 using cookies. Your cookie must expire after 2 minutes.

Create an index.html page with links to the three parts of the homework.

Suggestion: Start by working on problem 2; it is similar to problem 1, but smaller, and doesn't involve validation. Problem 1 will probably take the most time since it involves more programming.

When you are done with problems 2 and 1, make copies of all files you needed for problem 2 and rename them. Add a cookie to the first receiving script. Once you're sure the cookie is received by the browser, add data to the cookie and try to retrieve it with the second receiving script. Once this works, move form data to the cookie.

The difficult part in cgi scripting is that you are network transmissioin of data. If there is an error, you won't get an informative error message. File not found or forbidden messages are most likely wrong path and permissions issues. Internal server error is most likely an error in one of your scripts.