SPUG: Mailform
Jafaar Nyang'oro
seppy at mail.tanzatech.com
Sun Mar 12 12:59:36 CST 2000
SPUGers,
I've created the following script to process form input after it's being
filled out. I've writen it for a UNIX-based server.
I want to make it work on an NT environ as well. What changes should I make
on the script for it to be able to work on Windows NT server?
Thanks.
../seppy
#!/usr/bin/perl
#
#########################################################
#
# Author: Jafaar Nyang'oro - March 11, 2000
#
# This script receives vote inputs from voting form and
# sends them by e-mail to returning officers
#
#########################################################
# Address of the administrator
$admin = "seppy\@mail.tanzatech.com";
# Address of the Returning Officers
$returning_officers = "kura\@tanzatech.com";
# Parse the inputs from the form and store them
# in an associative array 'fields'
&parse_input(*fields);
# Read the Full Name of the voter
$realname = $fields{'real-name'};
# Remove leading and trailing spaces
$realname =~ s/^(\s+)|(\s+)$//g;
# Make sure the input is not an empty space
if (length($realname) == 0) {
&print_header;
print '<body bgcolor="white" text="red">';
print 'Please use the <b>Back</b> button of your browser, fill in your
<b>Full Name</b> and re-submit the form.';
exit;
}
# Read the e-mail address of the voter
$address = $fields{'sent-by'};
# Remove leading and trailing spaces
$address =~ s/^(\s+)|(\s+)$//g;
# Make sure the input is not an empty space
if (length($address) == 0) {
&print_header;
print '<body bgcolor="white" text="red">';
print 'Please use the <b>Back</b> button of your browser, fill in your
<b>Address</b> and re-submit the form.';
exit;
}
# Read the votes
$one = $fields{'one'};
$two = $fields{'two'};
$three = $fields{'three'};
$four = $fields{'four'};
$five = $fields{'five'};
$six = $fields{'six'};
$seven = $fields{'seven'};
$eight = $fields{'eight'};
# Now send the mail to the Returning Officers
open (MAIL, "|/usr/bin/sendmail $admin");
open (MAIL, "|/usr/bin/sendmail $returning_officers");
print MAIL "From: $realname <$address>\n";
print MAIL "To: Returning Officers <$returning_officers>\n";
print MAIL "Subject: TANZANET Kura 2000\n";
print MAIL "\n";
print MAIL "Mwenyekiti:\n";
print MAIL "$one\n";
print MAIL "\n";
print MAIL "Makamu Mwenyekiti:\n";
print MAIL "$two\n";
print MAIL "\n";
print MAIL "\n";
print MAIL "Katibu:\n";
print MAIL "$three\n";
print MAIL "\n";
print MAIL "Naibu Katibu:\n";
print MAIL "$four\n";
print MAIL "\n";
print MAIL "Mweka Hazina:\n";
print MAIL "$five\n";
print MAIL "\n";
print MAIL "Naibu Mweka Hazina:\n";
print MAIL "$six\n";
print MAIL "\n";
print MAIL "Mwenyekiti Utawala:\n";
print MAIL "$seven\n";
print MAIL "\n";
print MAIL "Mwenyekiti Mitambo:\n";
print MAIL "$eight\n";
print MAIL "\n";
close (MAIL);
# Display the vote success results
&print_header;
print "<title>TANZANET Kura 2000</title>\n";
print '<body bgcolor="#FFFFFF">';
print '<center><font color="blue" size="+2">THANK YOU FOR VOTING! <br><br>
YOUR VOTE HAS BEEN SUCCESSFULLY SUBMITTED TO THE RETURNING
OFFICERS!</font></center>';
sub form_method {
$method=$ENV{'REQUEST_METHOD'};
}
sub path_info {
$path=$ENV{'PATH_INFO'};
$path=~ s/\///;
$return=$path;
}
sub print_header {
if (!defined(@_)) {
print "Content-type: text/html\n\n";
}
else {
print "Location: @_\n\n";
}
}
sub parse_input {
if (defined(@_)) {
local(*input)=@_;
}
else {
local(*input)="*cgiinput";
}
local ($temp, at pairs);
if (&form_method eq 'POST') {
read(STDIN,$temp,$ENV{'CONTENT_LENGTH'});
}
else {
$temp=$ENV{'QUERY_STRING'};
}
if ($temp ne '') {
@pairs=split(/&/,$temp);
foreach $item(@pairs) {
($key,$content)=split (/=/,$item,2);
$content=~tr/+/ /;
$content=~ s/%(..)/pack("c",hex($1))/ge;
if (!defined($input{$key})) {
$input{$key}=$content;
}
else {
$input{$key} .= "\0$content";
}
}
return 1;
}
else {
return 0;
}
}
__________________________________________
NetZero - Defenders of the Free World
Get your FREE Internet Access and Email at
http://www.netzero.net/download/index.html
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
Email to majordomo at pm.org: ACTION spug-list your_address
More information about the spug-list
mailing list