Form in CGI not working :-\

blackwell4

Registered
Hello-

I wrote a cgi script for a contact form and it isn't working.

I would like to know if anyone could offer me some help please?

Here's the html part of the form:

--------------------------------------------------------

<form action="cgi/gdform.cgi" method="post">
<font class="trudy_bluebodytext">
First Name:<INPUT TYPE="text" NAME="first" SIZE="20"><br>
Last Name:<INPUT TYPE="text" NAME="last" SIZE="20"><br>
Phone Number:<INPUT TYPE="text" NAME="phone" SIZE="11"><br>
E-Mail:<input type="text" name="email" /><br>
Please type your message/question below:<br>
<TEXTAREA NAME="comment" ROWS="15 here" COLS="70 here"></TEXTAREA>
<br><br><center>
<INPUT TYPE="submit"><INPUT TYPE="reset">
</center>
</form>

--------------------------------------------------------

I don't think the problem is in the HTML...I think it's below in the actual script.


Here's the cgi script:

--------------------------------------------------------

#!/usr/bin/perl

@to = qw(
michael@blackwellmultimedia.com
trudy.krisher@sinclair.edu
);

$rootdir = "/cgi";
$dbase = "$rootdir/data/trudy.txt";

$date = `date \"+%d %h %Y\"`;
chop($date);

$time = 'date';
$cn = time;


$TITLE = "QCC: TrudyKrisher.com";

&initb;

#form_fields
$first = $FORM{'first'};
$last = $FORM{'last'};
$phone = $FORM{'phone'};
$email = $FORM{'email'};
$comment = $FORM{'comment'};


#check for missing field data
&missing_entry() unless $FORM{first};
&missing_entry() unless $FORM{last};
&missing_entry() unless $FORM{phone};
&missing_entry() unless $FORM{email};
&check_email;

#write the data to a file
&create_dbase;

#shift(@fields);
select(STDOUT); $| = 1;

&hdr;


print << "EOHTML";

<span class="hed">Thank you</span>
<P>Your request has been received.

EOHTML

&ftr;


# close(STDOUT);

if ($pid = fork) {
close(STDIN);
close(STDOUT);
} elsif ($pid == 0) {
#open(STDERR, ">>logs/fferrlog");
open(STDOUT, ">&STDERR");
warn "log test";
for $_to (@to) {
warn "log $_to\n";
next unless $_to;

unless (open(SM,"|/usr/sbin/sendmail -t -odb")) {
warn $!;
open(SM, ">&STDERR");
}
print SM $msg = "From: $email
Errors-To: $error
Return-Path: $error
To: $_to
Subject: TrudyKrisher.com
";
print SM "

Thank you for submitting your request. Your information has been recorded as the following.

Name: $FORM{first} $FORM{last}
Phone: $FORM{phone}
Email: $FORM{email}
Message/Question: $FORM{comment}

Thank you!
Trudy Krisher
www.trudykrisher.com
";

close(SM);
warn "to: $_to, from: $from, date: ".localtime()."\n";
}
}
else {
print "<HR><P>\n";
print "Form input was not processed. Please mail your ";
print "remarks to $to_field\n";
}




sub create_dbase {
open(DBASE, ">>$dbase") || die "I can't create $dbase\n";
print DBASE "$FORM{first}|$FORM{last}|$FORM{phone}|$FORM{email}|$FORM{comment}EOF\n";
close(DBASE);
}

sub email_error {
$url= "http://www.trudykrisher.com/error.html";
print "Location:$url\n\n";
exit;
}

sub missing_entry {
$url= "http://www.trudykrisher.com/required.html";
print "Location:$url\n\n";
exit;
}


sub check_email {
if ($email =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ ||$email !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/) {
&email_error;
}
else {
return 1;
}
}


sub initb {
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}
@pairs = split(/&/, $buffer);

foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
next if $name eq "name";
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/^\s+//;
$value =~ s/\s+$//;
$value =~ s/[\n]/ /g;
$value =~ s/[\r]/ /g;
$value =~ s/\t+/ /g;
$value = "yes" if $value eq "value";
if ($value ne "") {
if ($name eq 'msga') {
$FORM{$name} .= $value."\t";
}
elsif ($name eq 'msg') {
$FORM{$name} .= "\t". $value;
}
elsif ($name eq 'room_date') {
$FORM{$name} .= " ". $value;
}
else {
$FORM{$name} = $value;
}
push(@fields, $name);
}
}
}

sub hdr {

print "Content-type: text/html\n";

print <<"EOHTML";

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML>
<HEAD>
<meta http-equiv="content-type" content="text/html;charset=ISO-8859-1">
<title>THANK YOU</TITLE>


</HEAD>
<BODY>

<P><CENTER>

<!--START CONTENT-->
Trudy Krisher

EOHTML
}

########################

sub ftr {

print << "EOHTML";

<!--END CONTENT-->

</CENTER>
</BODY>
</HTML>

EOHTML
}


--------------------------------------------------------


Any help you may offer would be greatly appreciated. Thank you very much.
To get ahold of me personally, please email blackwell.12@wright.edu
 
Ooof. I think you haven't seen a response here because this is a big chunk of unformatted code, with no info on what errors you've encountered, what you've tried to address the errors, and so on.

If you provide some more info, someone might get back to you.
 
Thanks but I figured it out...the code and everything was correct but the hosting account [I'm an idiot] just wasn't setup to properly handle cgi scripts.

It's functional and up and running but thank you for your reply!
 
Back
Top