#!/usr/bin/perl
### Script7file.cgi
#### Include the perl module CGI.pm
use CGI qw( :standard);
#print( header() );
#### Extract values from form using param( ) function
$title = param( "title" );
$firstname = param( "firstname" );
$lastname = param( "lastname" );
$email = param( "email" );
$feedback = param( "feedback" );
$age = param( "age" );
$gender = param( "gender" );
$favoritemovies = param( "favoritemovies" );
$seenit = param( "seenit" );
$test = $email;
#### setting variables for cookie
#$title = $title;
#$lastname = $lastname;
$fullname = $title . $lastname;
#### setting the cookie
print "Set-Cookie: geno=$fullname\n";
print "Content-type:text/html\n\n";
#### Error checking for title, first name, last name
## This is the initial test for errors in title, firstname, and lastname fields
if ($title eq "" or
$firstname eq "" or
$lastname eq "" or
$email eq ""){
#### making error web page
print "
Geno Patterson -- Blank title, first, or last name";
print "The Information you submitted had some errors, you
can use the link below to correct the missing information
\n";
#### Test statements to test which field is blank
#### test for title
if ($title eq ""){
print "
You failed to specify a title, please go back and enter your title.\n\n
";
}
#### test for firstname
if ($firstname eq ""){
print "You failed to specify your first name,
please go back and enter your first name.
";
}
#### test for lastname
if ($lastname eq ""){
print "You failed to specify your last name,
please go back and enter your last name.
";
}
#### test for email
if ($email eq ""){
print "You failed to specify your e-mail address, please go back and enter your e-mail address.
";
}
#### Link back to form page
print "
Click here to reenter incorrect data.
";
#### closing error web page
print "";
}
###########################
#### Testing E-mail using regular expressions
###########################
#### The regular expression used: $test =~ /[\w\-]+\@[\w\-]+\.[\w\-]+/
# 1.[\w\-]+ -- match one or more (x+) set of alphanumeric (or dash) ([\w\-]) characters (\w -- alphanumeric and \- "escapes" the dash).
# 2.\@ -- followed by "@" (note the \ for "escaping" the "@" symbol)
# 3.[\w\-]+ -- See above
# 4.\. -- followed by "." (note the \ for "escaping the "." symbol)
# 5.[\w\-]+ -- See above
elsif ($test !~ /[\w\-]+\@[\w\-]+\.[\w\-]+/){
#### making error web page
print "Geno Patterson -- e-mail address test using regular expressions";
print "The Information you submitted had some errors, you
can use the link below to correct the missing information
\n";
#### test for the /@ symbol
if ($test !~ /\@/) {
print "You failed to input an @ symbol.
";
}
#### test for one or more alphanumeric characters before the @ symbol
if ($test !~ /[\w\-]+\@/) {
print "You failed to enter text before the @ symbol.
";
}
#### test for one or more alphanumeric characters after the @ symbol
if ($test !~ /\@[\w\-]/) {
print " You failed to enter text after the @ symbol.
";
}
#### test for one or more alphanumeric characters between the /@ symbol and the period
if ($test !~ /\@[\w\-]+\./) {
print " You failed to enter text between the @ symbol and the period.
";
}
#### Test for period
if ($test !~ /\./) {
print " You failed to include a period.
";
}
#### Test for characters following period
if ($test !~ /\.+[\w\-]/) {
print " You failed to enter text after the period.
";
}
print "
Your e-mail address should be in the form:
JohnDoe\@aol.com
";
#### Link back to form page
print "
Click here to reenter incorrect data.
";
#### closing error web page
print "";
}
######################
#### END OF ERROR PAGE
#### BEGINNING OF ELSE FOR THANK YOU PAGE
######################
else {
print "Geno Patterson -- Thank You Form";
print "Thank you for participating in the Signs movie survey";
print "
";
print "Your responses were...
";
#### title
print "- The title you specified was
$title.";
print "
- The first name you specified was
$firstname.
";
print " - The last name you specified was
$lastname.";
print "
- The E-mail address you entered was
$email.
";
print " - The feedback you entered was:
$feedback.
";
print " - The age you specified was
$age.
";
print " - The gender you selected was
$gender.
";
print " - The movies you selected were
$favoritemovies.
";
print " - Your response to having seen the movie or not was
$seenit.
";
print "
";
print "
";
#### Link to cookie reader
#### script7b.cgi
print "
Click here to check on cookie that was set ";
#### Open file for appending
if ($feedback ne ""){
open(OUTF,">>guestbookfile.htm");
print OUTF "
";
print OUTF "$feedback\n";
close(OUTF);
}
#### Link to guestbook.htm
print "
Click here to view my guestbook file
";
################
######## E-MAIL PART
$mailprog = '/usr/sbin/sendmail';
# change this to your own email address
# this opens an output stream and pipes it directly to the sendmail
# program. If sendmail can't be found, abort nicely by calling the
# dienice subroutine (see below)
open (MAIL, "|$mailprog -t") or &dienice("Can't access $mailprog!\n");
# here we're printing out the header info for the mail message. You must
# specify who it's to, or it won't be delivered:
print MAIL "To: $email\n";
#print MAIL "Cc: rs01\@swt.edu\n";
# Reply-to can be set to the email address of the sender, assuming you
# have actually defined a field in your form called 'email'.
print MAIL "Reply-to: $email $name\n";
# print out a subject line so you know it's from your form cgi.
# The two \n\n's end the header section of the message. anything
# you print after this point will be part of the body of the mail.
# NOTE: No more than ONE \n, otherwise the HTML header
# WON'T Work!!!
print MAIL "Subject: Form Data from $firstname $lastname\n";
# here you're just printing out all the variables and values, just like
# before in the previous script, only the output is to the mail message
# rather than the followup HTML page.
print MAIL <
EndHeader
;
print MAIL "Dear $title $lastname,
";
print MAIL "Thank you for participating in our survey of the movie Signs.
";
print MAIL "Your responses were as follows:
";
print MAIL "- The title you specified was
$title.";
print MAIL "
- The first name you specified was
$firstname.
";
print MAIL " - The last name you specified was
$lastname.";
print MAIL "
- The E-mail address you entered was
$email.
";
print MAIL " - The feedback you entered was:
$feedback.
";
print MAIL " - The age you specified was
$age.
";
print MAIL " - The gender you selected was
$gender.
";
print MAIL " - The movies you selected were
$favoritemovies.
";
print MAIL " - Your response to having seen the movie or not was $seenit.
";
print MAIL "
";
print MAIL "Sincerely Yours,
";
print MAIL "Geno Patterson
";
# when you finish writing to the mail message, be sure to close the
# input stream so it actually gets mailed.
close(MAIL);
# now print something to the HTML page, usually thanking the person
# for filling out the form, and giving them a link back to your homepage
print <
Thank you for your participation, $firstname. Your mail has been delivered.
Go Back to the
form?
EndHTML
;
}
sub dienice {
($errmsg) = @_;
print "
Error
\n";
print "$errmsg\n";
print "