I have managed to piece together (from looking at other's scripts) a very simple script that takes all of the elements sent to it via html form and arranges them and emails the results.
All I am trying to do now is add a little modification of making a few of the fields required. A problem, the script doesn't have the fields being sent to it hard coded into it so I can't easily put a simple
if ($firstname = "") in it. It loops, reading each name=value.
You can see below I tried just coding into the loop to check for if $name = "firstname" then check if $value = "".
But it doesn't work at all. I could use some help, hack at me all ya can!
#!/usr/bin/perl
$mailprog = "/usr/lib/sendmail";
$msg = "";
$send_to = "webmaster\@3dwc.com";
$subject = "Online Repair Status Inquiry";
$from = "Form Submission";
$ok_url = "/thanks.html";
$bad_url = "/nogo.html";
%f = &parseform;
foreach $key (sort keys %f) {
$mystring = "$key: $f{$key}\n";
$msg .= $mystring;
}
&sendmail($from,$send_to,$subject,$msg);
print "Location: $ok_url\n\n";
sub sendmail {
my($from,$to,$subject,@msg) = @_;
open(MAIL,"|$mailprog -t");
print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n\n";
print MAIL <<EndMail;
@msg
EndMail
close(MAIL);
}
sub parseform {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
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;
if ($name = "firstname"){
if ($value = ""){
die print "must enter first name";
}else{
#all is well
}
}elsif ($name = "lastname{
#all is well
}
}
return %FORM;
}