Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl -w
- #print a standard 200-levlel HTTP Header
- print "Content-Type:text/html\n\n";
- if ($ENV{'REQUEST_METHOD'} eq "GET") {
- #display form if GET request is used
- &survey();
- #}elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
- #Process form if POST method used
- # &displayInfo();
- }
- #the following code - in blue - wiil
- #get the data from the form, and store it in a hash named %form
- #get data from env var
- $qstring = $ENV{'QUERY_STRING'};
- #break data up on ampersands, and store it in an array
- @pairs = split(/&/, $qstring);
- #start a loop to process form data
- foreach (@pairs) {
- # split field name and value on '=', store in two scalar vars
- ($key, $value) = split(/=/);
- #translate '+' signns back to spaces
- $value =~ tr/+/ /;
- #translate special characters
- $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
- #store data in hash
- $form{$key} = $value;
- }
- #now the data is stored in the hash $form
- #send output to browser as HTML
- print "<html><head><title>Student Survey</title></head>\n";
- print "<body>\n";
- sub survey {
- print qq~
- <h1>Student Survey</h1>
- <form action="/cgi-stuff/part2.cgi" method="GET">
- Full Name: <input type="text" name="person"><br>
- Favourite Sport: <input type="text" name="sport"><br>
- Favourite Seneca Course: <input type="text" name="course"><br>
- Current GPA: <input type="text" name="gpa"><br>
- <input type="submit" value="send">
- <input type="reset" value="reset">
- </form>
- ~;
- }
- #display survey
- #&survey();
- #display form data
- &displayInfo();
- print "</body></html>\n";
- #This subroutine will display info received from a form
- sub displayInfo {
- print "Full Name:", $form{"person"}, "<br>";
- print "Favourite Sport:", $form{"sport"}, "<br>";
- print "Favourite Seneca Course:", $form{"course"}, "<br>";
- print "GPA:", $form{"course"}, "<br>";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement