7.12.2001
Dear Sirs,
I have been using an html form for gathering information to use in order to
give customers quotes on our products. I have the fields validated on the
client’s browser (javascript) before submission to the server. The form is
then parsed by formmail.pl, a script the host provided.
I have since loaded apache on my m$ machine as well as perl, in order to
learn how to do this in-house, so that I could go from design to webmaster.
I took the same form, reinserted my “form_parse.pl” in the input
tags on my page, but I can’t get the returned output. How do I get my
script to “email” my output to me (localhost) as well as print the output
to an html page after the submit button is clicked. Some code follows:
# From my Html Page
<form onSubmit = "return submitIt (this)" action =
"http://127.0.0.1/cgi-bin/form_parse.pl" name = "cattlemancustomForm">
<input
type="hidden" name="recipient" value="[EMAIL PROTECTED]">
<input
type="hidden" name="subject" value="Cattleman form submittal">
<input
type="hidden" name="title" value="Info">
# form_parse.pl #
# What do I need to incorporate into my script to email my output to me
(localhost)?
# Also, is this a good parsing script, or can it be improved?
# And finally, does my server (Apache for M$) need the *.conf file to be
changed in a way that will allow for email?
#!c:/perl/bin/perl -w
print "Content-type: text/html\n\n";
print header;
print "<HTML><HEAD><H1><B><CENTER>Check Form Perl
Script</CENTER></B></H1></HEAD>";
print "<TITLE>Nate's Form Parser</TITLE>";
sub Parse_Form {
if ($ENV{'REQUEST_METHOD') eq 'GET') {
@pairs = split (/&/,
$ENV{'QUERY_STRING'});
} elsif ($ENV{'REQUEST_METHOD'} eg
'POST') {
read (STDIN, $buffer,
$ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
if ($ENV{'QUERY_STRING'}) {
@getpairs =split(/&/,
$ENV{'QUERY_STRING'});
push (@pairs, @getpairs);
}
} else {
print "Content-type: text/html\n\n";
print header;
print "<P>Use Post or Get";
}
foreach $pair (@pairs) {
($key, $value) = split (/=/, $pair);
$key =~ tr/+/ /;
$key =~ s/%([a-fA-F0-9] [a-fA-F0-p])/
pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~s/%[a-fA-F0-9] [a-fA-F0-p])/
pack("C", hex($1))/eg;
$value =~/<!--(.|\n)*-->//g;
if ($formdata{$key}) {
$formdata{$key} .= ", $value";
} else {
$formdata{$key} = $value;
}
}
}
1;
print "Content-type: text/html\n\n";
print header;
foreach $key (sort keys(%formdata)) {
print "<P>The field named<B>$key</B>
contained <B>$formdata{$key}</B>";
}
########################################################
Thanks so much for any help.
Nathan Garlington
Internet Graphics and Design
www.tandrtrailer.com <http://www.tandrtrailer.com/>
[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
719.263.4432