#!/usr/bin/perl # A quick example that shows how to use CGI.pm to handle forms in Perl 5 # Chris Uriarte # well, do just what it says....use the CGI.pm module and import the standard set # of methods use CGI qw/:standard/; # create a CGI object in $cgi $cgi = new CGI; # you can get specific values from your form by using the 'param' method and specifying # the "name" or your HTML form field as an argument....for example: # Retrieve the value from the NAME and EMAIL fields, if present $email = $cgi->param("EMAIL"); $name = $cgi->param("NAME"); # Retrieve the Value from the COMMENT and CLASSTITLE fields $comment = $cgi->param("COMMENT"); $classtitle = $cgi->param("CLASSTITLE"); # Make sure that is at least a comment and class name are in the form # If either is empty, go to the &blankComment sub-routine and tell them # The &blankField field terminates the entire script if called if ($comment eq "" || $classtitle eq "") { &blankField(); } # If everything is OK at this point, sent the comment to me via email &sendMail(); # Now send a response back to the browser &sendResponse(); sub sendMail { # Specify the To: address - must escape out the @ in the email address $to_address = "chrisjur\@cju.com"; # Get the date and time $date = localtime(); #Open a pipe to the mail program and send mail open(MAIL, "|/usr/sbin/sendmail -t"); print MAIL "From: Anonymous Feedback\n"; print MAIL "Reply-to: $name <$email>\n" if $email; print MAIL "To: $to_address\n\n"; print MAIL "You have received feedback at $date.\n\n"; print MAIL "From: $name <$email>\n"; print MAIL "Class: $classtitle\n\n"; print MAIL "Comment: $comment\n\n"; close(MAIL); } #Send the response "Thank you" page back to the browser sub sendResponse { # Print out the "Content-type: text/html\n\n" header print $cgi->header(); # Print out the HTML page print <<"END";

Thank you for your comments!

Your comment:

$comment

was received. Thank you very much. END # We're done, so get outta here..... exit; } #Oops, they left the comment field blank sub blankField { # Print out the "Content-type: text/html\n\n" header print $cgi->header(); # Print out the HTML page print <<"END";

Sorry!

You have to enter a comment and a class name in the form. Please go back and try again.
END #End the entire CGI process exit; }