CIS 24: CGI and Perl Programming for the Web
Class 9 (11/6) Midterm Exam
General Guidelines
This exam is open book and open note. However, there is no talking (this includes online chats!). You have two hours to complete the exam. Read all of the instructions before starting your work.
Instructions
This exam asks you to create two scripts for processing submissions from a web form. You will use the same form with both scripts, and the form is provided for you.
To save time, you are strongly encouraged to copy-and-paste scripts from the lecture notes, and then modify them as necessary to meet the specific requirements of this Exam.
- Click on the following link to get the form. Once it's displayed in your browser, go to the browser's file menu, select "Save As," and save the file as E:\Program Files\Apache Group\Apache\htdocs\form.html. Get the form now. Then click your browser's back button to return to this page.
- Start the Apache web server on your computer. You can do this by going to the "Start" Menu, then go to "Programs", then "Apache Group", and then select "Start Apache".
- Confirm that you've got everything set up correctly. View form.html through your web server: http://localhost/form.html. Then click your browser's back button to return to this page.
- Using Notepad or EasyHTML, write your first Perl script. Use the methods we discussed in Class 7 to do the following:
- Receive the data from submissions of form.html and make it available for use. To do this, have your script detect whether the submission is GET or POST, remove the hexadecimal encoding of the data, and make the data available in a hash.
- Use pattern matching to test whether the user entered one or more word characters into each of the form fields, except for State and Zip Code. For those, test whether the user entered two letters for the State, and 5 digits for the Zip Code. If the user did not complete all the fields properly, dynamically generate a web page that tells the user which fields need to be corrected. Then exit the script.
- Display the data entered by the user in a web page. The page should have a layout like this:
Your Name and Address
First name: Mike
Last name: Toppa
Street Address: 16 Happy St.
City: Happytown
State: CA
Zip: 95030
- Save your script as E:\Program Files\Apache Group\Apache\cgi-bin\address1.pl - test it with the form and see if it's working. If it's not, try to debug it (follow the debugging steps outlined in last week's lecture), and make the necessary corrections to your script.
- Using Notepad or EasyHTML, write your second Perl script. Use the methods we discussed in Class 8 to do the following:
- Receive the data from submissions of form.html and makes it available for use. To do this, have your script invoke the CGI.pm module, and the data will be made available to you with the "param" function.
- Display the data entered by the user in a web page with the same layout used in your first script (you do not need to do form input validation). The page should also include a form with a text input box that asks for the user's phone number.
- After the form is submitted, have your script display all the information the user has submitted: first name, last name, street address, city, state, zip, and phone number.
- Save your script as E:\Program Files\Apache Group\Apache\cgi-bin\address2.pl - then test and debug it.
- When you're done with your scripts (or time is up), copy-and-paste them into the form fields below, and click the submit button.