Click to See Complete Forum and Search --> : [RESOLVED] Form submission script?


stormyeyedbear
06-19-2006, 04:19 PM
I have built a form for a website, and need a server-side script to process and send it. The script would preferably be CGI. my biggest problem is not knowing how to write the script.

<form action=" " method=post>

<font size="-1" face="verdana,arial"> </font>
<table width="400" border="4" align="center" cellpadding="0" cellspacing="0" bgcolor="#ffffcc">
<tr>
<td height="622" bgcolor="#296DCE"><table border="0" bordercolor="#296DCE" bgcolor="#BCD0E8">
<tr>
<td colspan="2" align="center" bordercolor="#BCD0E8" bgcolor="#296DCE"><h2><span class="style7"><font face="verdana,arial"><br />
Contact the I.A.H.C.N. </font></span> <span class="style8"><font face="verdana,arial"><br />
<br />
</font></span></h2></td>
</tr>
<tr>
<td width="30%" bgcolor="#BCD0E8"><strong><font face="verdana,arial" size="-1">Name:</font></strong></td>
<td width="70%" bgcolor="#BCD0E8"><font size="-1" face="verdana,arial">
<input type="text" size="25" name="realname" />
</font></td>
</tr>
<tr>
<td width="30%" bgcolor="#BCD0E8"><strong><font face="verdana,arial" size="-1">Rank/Title:</font></strong></td>
<td bgcolor="#BCD0E8"><font size="-1" face="verdana,arial">
<input type="text" size="25" name="ranktitle" />
</font></td>
</tr>
<tr>
<td width="30%" bgcolor="#BCD0E8"><strong><font face="verdana,arial" size="-1">Company:</font></strong></td>
<td bgcolor="#BCD0E8"><font size="-1" face="verdana,arial">
<input type="text" size="25" name="company" />
</font></td>
</tr>
<tr>
<td width="30%" bgcolor="#BCD0E8"><strong><font face="verdana,arial" size="-1">Address:</font></strong></td>
<td bordercolor="#296DCE" bgcolor="#BCD0E8"><font size="-1" face="verdana,arial">
<input type="text" size="25" name="address" />
</font></td>
</tr>
<tr>
<td width="30%" bgcolor="#BCD0E8"><strong><font face="verdana,arial" size="-1">Phone:</font></strong></td>
<td bgcolor="#BCD0E8"><font size="-1" face="verdana,arial">
<input type="text" size="25" name="phone" />
</font></td>
</tr>
<tr>
<td width="30%" bgcolor="#BCD0E8"><strong><font face="verdana,arial" size="-1">Fax:</font></strong></td>
<td bgcolor="#BCD0E8"><font size="-1" face="verdana,arial">
<input type="text" size="25" name="fax" />
</font></td>
</tr>
<tr>
<td bgcolor="#BCD0E8"><strong><font face="verdana,arial" size="-1">E-mail Address:</font></strong></td>
<td bgcolor="#BCD0E8"><font size="-1" face="verdana,arial">
<input type="text" size="25" name="email" />
</font></td>
</tr>
<tr>
<td colspan="2" bgcolor="#BCD0E8">&nbsp;</td>
</tr>
<tr>
<td align="center" bgcolor="#BCD0E8"><strong><font face="verdana,arial" size="-1">Subject:</font></strong></td>
<td bgcolor="#BCD0E8"><select name="subject" size="8">

<option value="conference info"><font size="-1" face="verdana,arial">Conference Information Request </font></option>
<option value="training info"><font size="-1" face="verdana,arial">Training Information Request </font></option>
<option value="membership info"><font size="-1" face="verdana,arial">Membership Information Request </font></option>
<option value="script bug"><font size="-1" face="verdana,arial">Site Errors / Missing Files </font></option>
<option value="general"><font size="-1" face="verdana,arial">General Site Comments </font></option>
<option value="suggestions"><font size="-1" face="verdana,arial">Suggestions </font></option>
<option value="questions"><font size="-1" face="verdana,arial">Questions </font></option>
<option value="misc"><font size="-1" face="verdana,arial">Miscellaneous </font></option>
</select></td>
</tr>
<tr>
<td colspan="2" align="center" bgcolor="#BCD0E8"><font size="-1" face="verdana,arial"><font face="verdana, arial" size="-1"><b><br />
Please enter your message below.</b>
<textarea name="comments" wrap="virtual" rows="7" cols="45"></textarea>
<br />
</font></font></td>
</tr>
</table>
<center>
<font size="-1" face="verdana,arial">
<input name="button" type="button" value="Submit">
<input type="reset" name="Reset" value="Reset">
<br />
</font>
</center></td>
</tr>
</table>
<font size="-1" face="verdana,arial"><br />
</font>
</form>

Could someone look at the form code above, and help me write a cgi script for sending that. I would greatly appreciate it. Thanks.

stormyeyedbear
06-20-2006, 09:07 AM
Any chance at someone helping me? I am in a real bind here. Please help me.

LeeU
06-20-2006, 09:28 AM
I would just suggest using the Master Feedback script (http://www.willmaster.com/master/feedback/index.shtml) . I use it and it works great. VERY easy to set-up.

Lee

stormyeyedbear
06-20-2006, 12:06 PM
Ok, so I gave your suggestion a shot and am still having issues.

I used an form generator on the master script site to create the form code. I then configured the MasterFeedback.cgi file as instructed. The code for both are below.

I uploaded the files to the appropriate locations on the server. When I tested form and clicked submit, the form seemed to work, but I got a message stating that the page could not be displayed. Now I am sure that I got the permissions, etc... set properly. Any help would be appreciated. Thanks.


Form Code

<form method="POST" action="http://www.iahcn.org/cgi/MasterFeedback.cgi">
<input type="hidden" name="thankyou" value="http://www.iahcn.org/thankyou.html">
<table border="0" cellpadding="3" cellspacing="0">
<tr>
<tr>
<td align="right">Your Name:</td>
<td><input type="text" name="realname" size="25"></td>
</tr>

<TR>
<TD width="50%"><div align="right"><font face="verdana, arial" size="-1">Rank/Title:</font></div></TD>
<TD><INPUT TYPE="text" SIZE="25" NAME="ranktitle"></TD>
</TR>

<TR>
<TD width="50%"><div align="right"><font face="verdana, arial" size="-1">Company:</font></div></TD>
<TD><INPUT TYPE="text" SIZE="25" NAME="company"></TD>
</TR>

<TR>
<TD width="50%"><div align="right"><font face="verdana, arial" size="-1">Address:</font></div></TD>
<TD><INPUT TYPE="text" SIZE="25" NAME="address"></TD>
</TR>


<TR>
<TD width="50%"><div align="right"><font face="verdana, arial" size="-1">Fax:</font></div></TD>
<TD><INPUT TYPE="text" SIZE="25" NAME="fax"></TD>
</TR>


<td align="right">Email Address:</td>
<td><input type="text" name="email" size="25"></td>
</tr>


<tr>
<td align="right">Telephone Number:</td>
<td><input type="text" name="x_telephone" size="25"></td>
</tr>
<tr>
<td align="right">Specify a subject:</td>
<td><select name="subject">
<option value=""></option>
<option value="Conference Information Request">Conference Information Request</option>
<option value="Training Information Request">Training Information Request</option>
<option value="Membership Information Request">Membership Information Request</option>
<option value="Site Errors / Missing Files">Site Errors / Missing Files</option>
<option value="General Site Comments">General Site Comments</option>
<option value="Sugguestions">Suggestions</option>
<option value="Questions">Questions</option>
<option value="Miscellaneous">Miscellaneous</option>
</select></td>
</tr>
<tr>
<td valign="top" align="right">Type your message here:</td>
<td><textarea name="message" cols="35" rows="6"></textarea></td>
</tr>
<td align="center" colspan="2"><input type="submit" value="Submit"></td>
</tr>
</table>
</form>


MasterFeedback code

#!/usr/local/bin/perl
#
# MasterFeedback Version 2.74
# Created July 5, 1999
# Version 2.75 completed July 30, 2005
# Author: William Bontrager of http://bontragerconnection.com/
#
# For tech support, see http://willmaster.com/support/
#
# Copyright 1998-2001 William Bontrager.
# Copyright 2002-2005 Bontrager Connection, LLC.
#
# This custom version of Master Feedback downloaded
# from: http://willmaster.com/master/feedback/genfeedback.shtml
# "Master Series CGI programs"
# <http://willmaster.com/master/>
# for: iahcn.org
# by: 71.97.205.120
# at: (1150815961) Tuesday, June 20, 2006 at 3:06:01 PM GMT.
#
# Before installing and/or using Master Feedback,
# you must agree to the complete license agreement
# linked at http://bontragerconnection.com/SoftwareLicenseAgreement.html
# or linked from http://willmaster.com/master/
#
# This software is licensed for use on domain iahcn.org
# while in compliance with the license agreement.
#
#===============================

# I N S T A L L A T I O N I N S T R U C T I O N S
#
#
# (1) Make sure the first line, at the top of this file, points to Perl 5+ on your server.
#
#
# (2) Specify the location of sendmail or qmail on your server.

$MailProgram = '/usr/lib/sendmail';

#
# (3) This program is designed to help you spam-proof your site. As such, you do
# not need to have your email address anywhere in the form, not even in a
# hidden field, where email harvesting robots can grab it.
#
# Instead of in the form, specify your email address here in the script.

$MyEmail = 'mwdurbin01@verizon.net';

#
#
# End of Installation Instructions.
#
# Please see the user's manual, MasterFeedbackManual.html, for additional instructions.
#
# When you're ready for advanced functionality, consider
# Master Form V3 from http://willmaster.com/master/formV3/
#
# For tech support, see http://willmaster.com/support/
#
#######################################################################################
#
#
# Please don't change anything below here unless you know what you're doing. All changes
# should be done within the instruction area itself, above.
#
#
#######################################################################################


sub ErrorHTML
{
my $ts = join '<li>',@_;
print "Content-type: text/html\n\n";
print <<HTML;
<html><body bgcolor="white"><blockquote><blockquote>
<h4>Notice:</h4><ul><li>$ts</ul>
</blockquote></blockquote></body></html>
HTML
exit;
} # sub ErrorHTML

sub Parse
{
my $buffer;
if ($ENV{REQUEST_METHOD} eq 'GET') { $buffer = $ENV{QUERY_STRING}; }
else { read(STDIN,$buffer,$ENV{CONTENT_LENGTH}); }
my @p = split(/&/,$buffer);
for(@p)
{
$_ =~ tr/+/ /;
my ($n,$v) = split(/=/,$_);
$n =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
$v =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
$v =~ s/(\<.*?)(embed|object|script|applet)(.*?\>)/${1}_${2}_$3/gis;
$In{$n} = $v;
}
} # sub Parse

sub DiscardExtraSpaces {my $s=$_[0];$s=~s/\A\s+//;$s=~s/\s+\Z//;$s=~s/\s\s+/ /g;return $s;}

sub ValidEmail
{
return 0 if $_[0] =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
return 0 if $_[0] !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,}|[0-9])(\]?)$/;
return 1;
} # sub ValidEmail

Parse;
$MailProgram .= ' -t' if $MailProgram =~ /sendmail\Z/;
$MailProgram .= ' -i' if $MailProgram =~ /sendmail/;
$In{realname} = $In{name} if $In{name};
ErrorHTML('A name must be provided.') unless $In{realname} =~ /\w/;
ErrorHTML('Please provide an email address.') unless $In{email};
ErrorHTML("The email address \&quot;$In{email}\&quot; appears to be invalid.") unless ValidEmail($In{email});
ErrorHTML("The name, \"$In{realname}\", appears to be incorrect. Maybe you typed an email address by mistake?") if $In{realname} =~ /\@/;
$In{realname} = DiscardExtraSpaces($In{realname});
$In{subject} = 'Master Feedback form submission' unless $In{subject};
$In{email} =~ s/[\n\r]|(?:\\x|\%)0[ad]/\[LineBreak\]/sig;
$In{realname} =~ s/[\n\r]|(?:\\x|\%)0[ad]/\[LineBreak\]/sig;
$In{subject} =~ s/[\n\r]|(?:\\x|\%)0[ad]/\[LineBreak\]/sig;
my $log = time;
open MAIL,"|$MailProgram";
print MAIL <<TO_END;
X-Script-Name: Master Feedback from WillMaster.com
X-Script-Location: $0
Content-type: text/plain; charset="ISO 8859-1"
X-mfLog: $log
To: $MyEmail
From: "$In{realname}" <$In{email}>
Subject: $In{subject}

Name: $In{realname}
Email: $In{email}
IP: $ENV{REMOTE_ADDR}
Form: $ENV{HTTP_REFERER}
Message:
$In{message}
-----
TO_END
for (sort keys %In)
{
next unless /\AX[\_\-]/i;
$tt = substr($_,2);
print MAIL "$tt\: $In{$_}\n";
}
close MAIL;
unless($In{thankyou}) { $In{thankyou} = $In{redirect} ? $In{redirect} : $ENV{HTTP_REFERER}; }
print "Location: $In{thankyou}\n\n";

LeeU
06-20-2006, 12:35 PM
You stated
I got a message stating that the page could not be displayed.

What was the error? What page could not be displayed? Is therre a link to the contact page you are testing?

stormyeyedbear
06-20-2006, 01:21 PM
The link to the contact page in question is http://www.iahcn.org/contact2.html

The error message says the page cannot be displayed.

HTTP 500 - Internal server error
Internet Explorer

The URL in the address bar when I get that message is:
http://www.iahcn.org/cgi/MasterFeedback.cgi

When the submit button is clicked, the form is supposed to be processed, and the user is supposed to be sent to a thank you page at:
http://www.iahcn.org/thankyou.html

LeeU
06-20-2006, 02:25 PM
You are receiving a 500 error. First some questions:

1. Is the line at the top of the MasterFeedback file the correct path to your Perl directory (do you have Perl 5+?)

2. Is that the correct path to the sendmail script on your server?

3. When you uploaded the script, did you change the file permissions to 755?

4. Did you upload the file in ASCii format?

If you want, you can e-mail me at lunderwood@jupitermedia.com

stormyeyedbear
06-20-2006, 06:13 PM
The MasterFeedback file has the correct paths for Perl and Sendmail.
Permissions were changed to 755.

I think the problem may be in the file format. How to I change the file from binary to ASCii?

LeeU
06-20-2006, 10:34 PM
Just reload the file in ASCii format. That will take care of it.

stormyeyedbear
06-21-2006, 11:23 AM
I got it all working properly now. Thank you for all of your help.

LeeU
06-21-2006, 11:38 AM
Hey, no problem. That's what we're here for. Glad I could help.