Assignment 6
Due Tuesday 11/24 at the start of class
When you are done, send me an e-mail message. Also, hand in a printout of
all three scripts.
You may use the parse-lib.pl file which contains a function named
get_query. To access this, include the following statements in your
scripts
require '/home/scsfac/downeyt/scripts/parse-lib.pl';
%query = &get_query;
After these commands. %query will be the associative array of name/value
pairs of any parameters sent to your script. This function only works for
the GET and POST methods.
You are to create an HTML document in the root of your server named
scripts.html. On this page you will have links to two scripts:
random.pl and confirm.pl
-
random.pl
-
Use the GET method.
-
The script will look at the time of day, and check the seconds.
-
The script will display three completely different pages, depending on wether
the seconds have a remainder of 0, 1, or 2 when divided by 3.
-
Each page should contain a different title, pithy phrase, alignment, background
color and text color.
-
Each page should have a submit button that calls the script again.
This will allow the user to redisplay the page, probably with a different
page (but not always a different page).
-
Each page should also contain a count of how many times each of the different
pages has been displayed. Display the three totals in a table. Label each
total so it is easy to tell which page each total refers to.
-
Notes
-
Use this command to get the current seconds:
/usr/bin/date +%S
-
Use the chomp command to remove the final carriage return from the
seconds:
chomp($seconds)
-
Use the % operator to get the remainder when dividing by three:
$page
= $seconds
% 3
$page will now have the value of 0, 1, or 2.
-
Use the ++ operator to add 1 to a total:
$one++
-
Use three hidden fields to store the three page totals. Each time the page
is loaded it should retrieve the value of these three totals from the query
string into three variables. Increment one of these variables each time the
script is called. Use all three to update the contents of the table of totals.
-
-
confirm.pl
-
Use the POST method
-
When this script is called with no parameters, then display a form that has
a text field for the user's name, a text field for the user's phone number,
and a series of checkboxes for favorite colors: red, blue, green (or whatever
you want to specify). The user may select more than 1 color . have a submit
button labeled Submit.
-
Create a table so that all the form elements are aligned nicely.
-
Make all the fields required. When the form is submitted with parameters,
the script must check that the all the fields have been filled in.
-
If any of the fields are empty, then. If any of the fields is empty, then
display an error message and indicate in some way which fields still need
to be filled in. When the form is redisplayed, all the fields that were filled
in should be displayed with the values that the user already entered.
-
Also, validate each non-empty field.
-
The Name field should only contain letters, commas, periods, spaces and hyphens.
If not, then display an error message and indicate that the Name field must
be filled in again. When the form is redisplayed, all the fields that were
filled in should be displayed with the values that the user already entered.
-
The Phone field should be in the format (999) 999-9999, 999-999-9999, or
9999999999. Any number of spaces may be included anywhere in the number.
If it is not in the format, then display an error message and indicate that
the Phone field must be filled in again. When the form is redisplayed, all
the fields that were filled in should be displayed with the values that the
user already entered.
-
If all of the required fields are filled in and validated, then redisplay
the page with all the user's data in text format only (not in form elements),
and ask the user to confirm that the information is correct. Change the phone
number to the format (999) 999-9999 regardless of the format the user used.
Have two buttons: Correct and Incorrect. Be sure each button
has a name which can be tested by the script to determine which button was
pushed. Incorrect allows the user to change any fields, it will redisplay
the previous form with all the data displayed in the original form elements.
Correct writes the data to a file and displays a thankyou message
with another button that when clicked will display the contents of the file.
-
Notes
-
You can also use
scalar %query
to determine if the query associative
array has any elements. however, this time, scalar returns true if it has
elements and false if it doesn't.
-
You will need hidden fields to allow the script to remember the data
that was entered by the user.