PDA

View Full Version : Form processor doesn't seem to accept checkboxes..


AshleyQuick
01-29-2004, 07:13 AM
This form processor doesn't seem to allow for checkboxes. If you'll look for the line that begins with @fields =, I believe only text fields and textareas will work. Can this be modified to accept checkboxes?

#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);

##### SCRIPT SETUP
# Input your email address below.

# Note: Leave a backslash "\"
# in front of the @ sign!
$E_Mail = "info\@xyz.net";

# What is the location of your sendmail program?
# If you aren't sure, contact your web host.

$Mail_Program = "/usr/sbin/sendmail -t";


# If you aren't including an "email" field on the form(s)
# to be processed, who should the emails appear "From"?

$From_Address = "info\@xyz.net";


# If you aren't including a "subject" field on the form(s)
# to be processed, what should their subject be?

$Subject = "xyz Project Inquiry";

# Do you wish to send an automated reply to user? If yes,
# you will have to include the "email" field in your form(s).
# If yes, insert the location of reply.txt below.

# 1 = yes # 0 = no
$Send_Reply = "1";
$Reply_Template = "prodreply.txt";

# Where should users be redirected after a successful submit?

$Return_Link = "http://www.xyz.net/thanks.php";

# Do you wish to keep logs of all forms processed on your server?
# If so, they will appear in the "submitted" directory.

# 1 = yes # 0 = no
$Log_Forms = "1";

$Web_Address = "http://www.xyz.net";

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

if ( $ENV{'REQUEST_METHOD'} eq "POST" ) {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
} else { $buffer = $ENV{'QUERY_STRING'}; }
@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; }

@months = ("January","February","March","April","May","June","July",
"August","September","October","November","December");

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year += 1900; $month = $mon + 101; $day = $mday + 100; $date = "$months[$mon] $mday, $year";
$time = "$hour\:$min\:$sec";

@fields = ('Name','Company','Phone','Product','Question','EmailOne','EmailTwo');

open(MAIL,"|$Mail_Program") || &noprogram;
print MAIL "To: $E_Mail\n";

if (! $FORM{'email'}) {
print MAIL "From: $From_Address\n";
} else {
print MAIL "From: $FORM{'email'}\n";
}

if (! $FORM{'subject'}) {
print MAIL "Subject: $Subject\n\n";
} else {
print MAIL "Subject: $FORM{'subject'}\n\n";
}

print MAIL "Submitted at $time on $date...\n\n";

foreach $field(@fields) {
if ($FORM{$field}) {
if ($field eq "main") {
$FORM{'main'} =~ s/\Q\n\E/\n/g;
print MAIL "$field = $FORM{'main'}\n";
} else {
print MAIL "$field = $FORM{$field}\n";
}
}
}
close(MAIL);

if ($Send_Reply eq "1") {
open(REPLY,"$Reply_Template");
@reply = <REPLY>;
close(REPLY);

foreach $line(@reply) {
$line =~ s/\Q\n\E/\n/g;
$fiction .= $line;
}

open(MAIL,"|$Mail_Program") || &noprogram;
print MAIL "To: $FORM{'EmailOne'}\n";
print MAIL "From: $E_Mail\n";
print MAIL "$fiction\n\n";
print MAIL "\n\n\nNote: This message was not sent unsolicited. It was sent through a form located at $Web_Address. If you believe this message was received on error, please disregard it.";
close(MAIL);
}


if ($Log_Forms eq "1") {
if ($FORM{'EmailOne'}) {
open(LOG,">>prodsubmitted/$date.txt");
print LOG "Submitted at $time on $date...\n\n";
foreach $field(@fields) {
if ($FORM{$field}) {
if ($field eq "main") {
$FORM{'main'} =~ s/\Q\n\E/\n/g;
print LOG "$field = $FORM{'main'}\n";
} else {
print LOG "<p>$field = $FORM{$field}\n";
}
}
}
print LOG "\n";
print LOG "---------------------------\n\n";
close(LOG);
}
}

print qq~
<HTML>
<HEAD>
<META HTTP-EQUIV=Refresh CONTENT=0;URL="$Return_Link">
</HEAD>

<BODY></BODY>
</HTML>
~;
exit;

sub noprogram {
print qq~
Sendmail program failed to open!<br>
Message NOT sent.<br>
Please contact the webmaster about this problem.
~;
exit;
}

Paul-Ecchi
01-29-2004, 05:13 PM
You don't need to modify the Perl, you need to modify the form on the html page, post a copy of that and I'll look at it.

AshleyQuick
01-29-2004, 06:27 PM
Here's the form:

<table class="indent">
<form action="/cgi-bin/phpprodfp.cgi" method="post" onsubmit="return verify(this.EmailOne, this.EmailTwo)">
<tr>
<td class="formtext" id="pagetext1">Name</td>
<td><input name="Name" type="text" maxlength="65" onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';"></td>
</tr>
<tr>
<td class="formtext3" id="pagetext2">Company</td>
<td><input name="Company" type="text" size="27" maxlength="65" onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';"></td>
</tr>
<tr>
<td class="formtext3" id="pagetext3">Phone</td>
<td><input name="Phone" type="text" size="27" onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';"></td>
</tr>
<tr>
<td colspan="2" class="formtext2" id="pagetext4">Product<br>
<a class="icon" href="/products/Toolbar"><img alt="GateQuest ToolBar" width="20" height="24" src="/art/icon.ToolBar.gif"></a><input class="prodchex" type="checkbox" name="Toolbar" value="Toolbar">&nbsp;&nbsp;&nbsp;&nbsp;
<a class="icon" href="/products/Site_Recommender"><img alt="GateQuest php Site Recommender" width="20" height="24" src="/art/icon.phpSiteRecommender.gif"></a><input class="prodchex" type="checkbox" name="Site_Recommender" value="Site_Recommender">&nbsp;&nbsp;&nbsp;&nbsp;
<a class="icon" href="/products/File_Manager"><img alt="GateQuest php File Manager" width="20" height="24" src="/art/icon.phpFileManager.gif"></a><input class="prodchex" type="checkbox" name="File_Manager" value="File_Manager">&nbsp;&nbsp;&nbsp;&nbsp;
<a class="icon" href="/products/News_Content_Manager"><img alt="GateQuest php News/Content Manager" width="20" height="24" src="/art/icon.phpNews_ContentManager.gif"></a><input class="prodchex" type="checkbox" name="News_Content_Manager" value="News_Content_Manager"></td>
</tr>
<tr>
<td colspan="2" class="formtext2" id="pagetext5">Question/Comment
<br> <textarea name="Question" rows="5" cols="31" onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';"></textarea>
</td>
</tr>
<tr>
<td class="formtext" id="pagetext6">Email</td>
<td><input name="EmailOne" type="text" size="27" onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';"></td>
</tr>
<tr>
<td class="formtext" id="pagetext7">Confirm Email</td>
<td><input name="EmailTwo" type="text" size="27" onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';"></td>
</tr>
<tr>
<tr>
<td><input class="send" onClick="return checksubmit(this)" type="submit" value="Send Form"></td>
<td><input class="reset" type="reset" value="Reset Form" onclick="return confirm('Please confirm or cancel the reset.')"></td>
</tr>
</form>
</table>

...and here's how it appears in the email:

Submitted at 13:26:21 on January 29, 2004...

Name = Ashley
Company = XYZ
Phone = 123-4567
Question = Test
EmailOne = name@email.com
EmailTwo = name@email.com

Notice how the data for the checkboxes isn't even appearing? I'm sure it's something simple. Ugh! :(

Paul-Ecchi
01-30-2004, 08:10 AM
You have specified different field names in the form to the ones you have specified in the script. In the script, look at your list @fields, you have not listed the "names" of your checkbox fields, instead you have typed in the paragraph heading. Try replacing "Product" with the correct field names (ie @fields = ('Name','Company','Phone','Toolbar','Site_Recommender','File_Manager','News_Content_Manager','Questi on','Em ailOne','EmailTwo');

This may not give you the result you expected (as I assume you were hoping "product" would give you a list of the checked boxes) but it should get all the information mailed to you (assuming no other errors).