E301/Web Publishing: Hypertextual Theory and Design, Michael O'Conner

CGI and FORMS, E301
Section 1, 9:30-10:45


[Introduction] [Syllabus] [Assignments/Grading] [Policies] [New Student Pages][Old Student Pages]
First, take a look at the scripting for FORMs at: Millikin Get Information Form

Next, take a look at the perl script that runs the form on our local unix box:

#!/usr/local/bin/perl

# required hidden fields:
# recipient 'webman@millikin.edu'
# subject - subject of the message
# redirect - url to load when form is submitted

# use name="E-mail" for e-mail address field

# Check path to your e-mail program and change path if it is different
# from below

$mailprog = '/usr/lib/sendmail';


$date=`date +%D`;
$date=~s/\n$//;

$formdata=;
$formdata=~s/\s+$//;

foreach (split(/&/, $formdata))
{
($name, $value)=split(/=/, $_);
$name=~s/\+/ /g;
$name=~s/%([0-9|A-F]{2})/pack(C,hex($1))/eg;
$value=~s/\+/ /g;
$value=~s/%([0-9|A-F]{2})/pack(C,hex($1))/eg;

# if ($value eq "")
	#{
	#&exit($name);
	#}

if ($name ne "recipient" && $name ne "subject" && $name ne "redirect")
	{
	push (@print, $name)
	}
	

$data{$name}=$value;
}
if ($data{'E-mail'} ne "" && $data{'E-mail'} !~ /^[\w\.-]+@[\w\.-]+$/)
	{
	print "Content-type: text/html\n\n";
	print "

";
	print "Please enter correct e-mail address.";
	exit;
	}
 

open(MAIL, "|$mailprog -t") || die "Can't open $mailprog!\n";
print MAIL "To: $data{'recipient'}\n";
print MAIL "From: $data{'E-mail'}\n";

 #print MAIL "Cc: $data{'E-mail'}\n";

if ($data{'subject'}) 
{
   print MAIL "Subject: $data{'subject'}\n\n";
}

else {
   print MAIL "Subject: WWW Form Submission\n\n";
}

foreach (@print)
	{
	print MAIL "$_: $data{$_}\n";
	}


close MAIL;

print "Location:  $data{'redirect'}\n\n"; 

sub exit
{
local ($name)=@_;
print "Content-type: text/html\n\n";
print "

";
print "Your must fill in $name to process this form.";
print " Please return back and do it. Thank you.";
print "";
exit;
}

Return to O'Conner's Millikin Home Page

Last modified October,1997. Contact: moconner@mail.millikin.edu