• 0

[CGI] Form Help Please


Question

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 Michael@BlackwellMultimedia.com

Link to comment
https://www.neowin.net/forum/topic/483270-cgi-form-help-please/
Share on other sites

1 answer to this question

Recommended Posts

  • 0

If the script runs but doesn't grab the form fields, try changing the method=... line in your HTML to have POST in all capitals, as you compare it to "POST" later on in the cgi script:

if ($ENV{'REQUEST_METHOD'} eq 'POST') {

Also, use code tags

Otherwise, give a better explanation as to the problem.

XgD

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Been happy with Windows 11 myself even since first release in 2021, sure it hasn't always been perfect, but nothing is per say.. Issues i did have was minor ones, which is normal with any OS really. I still use Windows 10 at times on my unsupported Gaming Laptop, and i find myself using the Windows 11 Desktop more. Eventually replacing Gaming Laptop with a Windows 11 Compatible one somehow, someway this year or possibly next year at the latest, but its gonna happen--(May save all my Bing reward points except the 1000 to have extended support for 10) then work on getting quality Replacement hard)
    • Geez, this is dumb. I use my laptop sometimes in the dark when doing astrophotography to control my astro-PC... this explains why I have to keep entering my PIN when logging back in. So stupid. I can't see the keyboard in the dark, and I can't have lights everywhere to light it up because everything is very light sensitive (including my eyes!).
    • Naturally. I don't care about brand loyalty at all as it's all about price/performance/reliability etc (even what RejZoR said below is a great point to). basically bang-for-the-buck. because at the end of the day... one wants the cheapest possible price to maintain a certain minimum level of performance (or thereabouts). because generally after a certain point with CPU and GPU's the price starts to sky rocket without that much difference in performance where it really matters. p.s. historically I have bought more Intel CPU's and NVIDIA GPU's but I have had some AMD CPU's and one AMD GPU.
    • Both of these companies as well as Qualcomm and Apple need competition. Otherwise, they just coast. I don't prefer macOS, though I like some of Apple's hardware, but if anyone needs competition, it is Apple. Their prices are already outrageous and they need to have a reason to produce good hardware and at least keep prices remotely reasonable. (It is criminal what they charge for RAM upgrades especially.) Qualcomm needs to push AMD and Intel not to be so sloppy with the performance/efficiency aspect. Granted, AMD has been doing quite well in this respect considering they are not an ARM architecture. I personally want to have more options that truly compete with Macbook Air and Macbook Pro's on the Windows side. It is difficult to achieve what Apple does since they control the entire stack and that is fundamentally different for Windows PCs other than maybe Microsoft Surface PCs.
  • Recent Achievements

    • Week One Done
      Hartej earned a badge
      Week One Done
    • One Year In
      TsunadeMama earned a badge
      One Year In
    • Week One Done
      shaheen earned a badge
      Week One Done
    • Dedicated
      Cole Multipass earned a badge
      Dedicated
    • Week One Done
      Alexander 001 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      571
    2. 2
      ATLien_0
      182
    3. 3
      +FloatingFatMan
      182
    4. 4
      Skyfrog
      111
    5. 5
      Som
      106
  • Tell a friend

    Love Neowin? Tell a friend!