#! /usr/bin/perl

use CGI ':standard';
use CGI::Carp "fatalsToBrowser";
# W. Sterner CS101   -- Homework 5, Problem 3 Form a 

#3. Server-side Validation (50 pts.) 
#Create a cgi script that validates form data sent to the server
#via the HTML form created for problem 2.  The script must check 
#that required data has been submitted and whether the data is of
#the right kind, as specified below.
#Required data are:
#first name (must not be empty),
#last name  (must not be empty),
#address    (must not be empty),
#city       (must not be empty),
#state      (must be a string of two letters, save in upper case),
#zip        (must be a string of five digits),
#email      (a string that must contain one '@' and at least one '.')
#area of expertise (at least one recognized choice* must have been submitted)
#(* A 'recognized choice' is one of the values in your form page.)
#If one or more data fields do not meet the requirements, the form and 
#data must be returned to the user with a message indicating the problem.
#With the exception of radio and checkbox fields, valid data must appear 
#in the corresponding form fields.
#Finally, when the data has been validated and found correct, the user 
#must be notified about the acceptance of the data on another HTML page.
#

    print header, start_html('Get Personal & Preference Data');
print br;

print '<form action="http://people.cs.uchicago.edu/~sterner/cs101/testpl/pg53ba.pl" method="post">';

print 'Please enter the following personal data and area of expertise <br/> for your application.<br/><br/>';

print     'First name:  <br/>';
print '<input type="text" size="15" maxlength="20" name="Fname">';
print br, 'Last name:  <br/>';
print  '<input type="text" size="15" maxlength="20" name="Lname">';
print br, 'Address:  <br/>';
print  '<input type="text" size="15" maxlength="20" name="Address">';
print br, 'City:  <br/>';
print  '<input type="text" size="15" maxlength="20" name="City">';
print br, 'State:  <br/>';
print  '<input type="text" size="2" maxlength="2" name="State">';
print br, 'Zip: <br/>';
print '<input type="text" size="5" maxlength="5" name="Zip">';
print br, 'Email:  <br/>';
print  '<input type="text" size="20" maxlength="30" name="Email">';

print br, br,'Area of Expertise: <br/>';
print '<select name="expert" size=1>';
print '<option selected>No Selection</option>';
print '<option > Dance Critic</option>';
print '<option > Film Critic</option>';
print '<option > Literary Critic</option>';
print '</select>';

print br,br, '<input type=submit value="Submit Personal Data">';
print '<input type=reset value="Erase and Restart">';




print '</form>', end_html;
