|
Fall Semester 2007 |
Each part has two parts: a warm-up and an exercise. We'll work them out both in class.
Part One (Tuesday lecture).
The warmup:
$ENV{SCRIPT_NAME}.
Call this partOne and place it in your cgi-bin folder.
Call the form partOne.html and put it in htdocs.
Make the form submit the data to the program partOne in your cgi-bin.
partOne (the program) to also print $ENV{QUERY_STRING} when called. Use the form to send some data to the program. What do you notice?
Call the program counter and place it in cgi-bin next to the other program.
balance is noticed on the URL make the program report it.
So if the URL is counter?balance=6 the program should report the balance (as an
<h1>) then the link as before.
How does the program work now? What does it do?
#!/usr/bin/perl
use CGI; # import the CGI.pm module (library)
$q = new CGI; # data binding: create object $q that parses and stores incoming data
print $q->header, $q->start_html; # instance methods header and start_html produce strings for corresponding HTML sections
print $q->param('balance'); # the value associated with balance (if any) is extracted, and printed
print $q->end_html; # print the string for the end of HTML document, produced by instance method end_html
Try rewriting one of the two programs discussed above (e.g.,
counter) using this
information.
Part Two (Thursday lecture).
The warm-up:
portfolio) that prints four links and a picture.
Put the program in cgi-bin, make it executable,
test it. Here's the model.
Have the program report what's being asked (the param and the value or, at the very least, the query string).
Play with this script to clarify what that means if it's unclear.
counter
program from Part One using one textfield and one submit button only (no embedded links).
Hint: textfield's name is balance so you can store your state there.
(Ugly, perhaps, but functional. What if the textfield becomes a hidden field?)
calculator by adding textfields in the interface to indicate
Can you implement
something like the Flag Quiz (the program is almost complete).