#!/usr/bin/perl if ($ENV{'REQUEST_METHOD'} eq 'POST') { read( STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); }elsif ($ENV{'REQUEST_METHOD'} eq 'GET') { $buffer = $ENV{'QUERY_STRING'}; } else { #Format an error message to the user &html_header("Comment Form Error"); print "

\n"; print "Form input was not processed. Please mail your\n"; print "remarks to ernie@trierra.org\n"; &html_trailer; } #Split the name-value pairs on '&' @pairs = split(/&/, $buffer); # Go through the pairs and determine the name # and value for each form variable. 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; } # Step 4 # Now all the form variables are in the $FORM associative array # Create a text message to be sent to the user and written to a file $textmessage = "Subject: Shipping information from $FORM{fullname}\n \n" . "This is the shipping information submitted \n" . "$FORM{fullname}\n \n" . "$FORM{address1} \n" . "$FORM{address2} \n" . "$FORM{city} \n" . "$FORM{state}, $FORM{zip}\n" . "Phone: $FORM{phone1}-$FORM{phone2}-$FORM{phone3}\n" . "Membership Level: $FORM{level}\n" . "backpack ? : $FORM{backpack}\n" . "Birdwatching Book ? $FORM{book}\n" . " Bumper Sticker ? $FORM{bumper}\n" . " No Gift ? $FORM{nogift}\n" . "Credit Card Type $FORM{payment}"; # Check to see if an email address wa submitted if ($FORM{email} ne "") { #Before proceeding, validate the keyed in e-mail address for # evil characters if ($FORM{email} !~ /^[a-zA-Z0-9._\-+ \t\/@%]+$/) { &html_header("Illegal Email Address"); print "


\n"; print "The Email address you entered contains illegal \n"; print "characters. Please back up, correct, then and resubmit \n"; &html_trailer; exit; } #The users email address is clean, so open up #the email message to send a conformation to the user # construct email message $emailMessage = "To: $FORM{email}\r\n" . "From: info\@trierra.org\r\n" . $textmessage; open(MESSAGE, "| mail $FORM{email}"); print MESSAGE $emailMessage; # Format e-mail header information. #print MESSAGE "To: $FORM{email}i\r\n"; #print MESSAGE "From: info\@trierra.org\r\n"; #Write the actual e-mail message # print MESSAGE $textmessage; close (MESSAGE); } #Open file membershipInformation for writing and write information to the file open(REPORT, "> ../membershipInformation") or die("Couldn't open membershipInformaition\n"); print REPORT $textmessage; close (MESSAGE); # Thank the user and acknowledge the feedback &html_header("Thank you for joining Trierra!"); print "


\n"; print "This is the membership information submitted
\n"; print "$FORM{fullname}
\n"; print "$FORM{address1}
\n"; print "$FORM{address2}
\n"; print "$FORM{city}
\n"; print "$FORM{state}, $FORM{zip}
\n"; print "Phone: $FORM{phone1}-$FORM{phone2}-$FORM{phone3}
\n"; if ($FORM{backpack}) { print "backpack ordered \n"; } if ($FORM{book}) { print "Bird Watching book ? : $FORM{backpack}\n"; } print "

\n"; &html_trailer; # # ================== # This Subroutine takes a single input parameter and uses it as the # and first level header #================== sub html_header{ $document_title = $_[0]; print "Content-type: text/html\n\n"; print "<html>\n"; print "<head>\n"; print "<title>$document_title\n"; print "\n"; print "\n"; print "

$document_title

\n"; print "

\n"; } #================= # This subroutine finishes of the HTML stream #=============== sub html_trailer{ print "\n"; print "\n"; }