#!/usr/bin/perl # Tom Blum # June 2007 # IWA-HWG Homework/ Instructor M. Kowalski #read in a string sent by the POST method of a calling page (week6_form.html) read(STDIN,$buffer, $ENV{'CONTENT_LENGTH'}); #$buffer variable to use for debugging purposes #$buffer="submit=Submit&Spec=Thomas+Blum&home=yes&capab=yes&internal=no&email=yes&connect=hspeed&hphone=999-999-9999"; #parse the $buffer variable and create a hash #the expected name-value pairs are: # submit Submit (from submit button input) # Spec StudentName (from select) # home Yes/No (from radio input) # capab Yes/No (from radio input) # internal Yes/No (from radio input) # email Yes/No (from radio input) # connect dialup, etc. (from radio input) # hphone 999-999-9999 (from text input) # @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } my($sec, $min, $hour, $day, $mon, $year, $wday, $yday, $isdst) = localtime; $year += 1900; $today = ($mon+1) . "/" . $day . "/" . $year; #open and select file to append data to $filename="student_log.csv"; open STUDENT_LOG, ">>" . $filename or die "Problem creating file: $!"; select STUDENT_LOG; #prepare line to add to data file $line = join ",", $today, $FORM{Spec}, $FORM{home}, $FORM{capab}, $FORM{internal}, $FORM{email}, $FORM{connect}, $FORM{hphone}; #write line to data file print "\n$line"; close STUDENT_LOG; select STDOUT; &start_html; &html_head("Week 6 Form Response"); #argument is title print "

" . $FORM{Spec} . ". Thank you!

\n"; print "

" . $today . "

\n"; &start_html_table; #while (($key, $value) = each(%FORM)) #{ # &make_html_table_row($key, $value); #} #better control of order to make same as user form &make_html_table_row("Home Access", $FORM{home}); &make_html_table_row("Capable?", $FORM{capab}); &make_html_table_row("Access to Internal", $FORM{internal}); &make_html_table_row("Access to email", $FORM{email}); &make_html_table_row("Connection Method", $FORM{connect}); &make_html_table_row("Home phone", $FORM{hphone}); &end_html_table; &end_html; ################################################################################# sub start_html { print "Content-type: text/html\n\n"; } ################################################################################ sub html_head { print "\n\n"; print @_[0]; print "\n\n"; } ################################################################################ sub end_html { print "\n\n"; } ############################################################################### sub start_html_table { print "\n"; } ############################################################################### sub end_html_table { print "
\n"; } ############################################################################### sub make_html_table_row { print ""; foreach (@_) { print "" . $_ . ""; } print "\n"; }