I have an html Orderform for safety products for our employees, consisting of checkboxes. The user checks whichever items they want. No quantities are involved, it is always just 1 item.
Example:
And so on, I have over 40 items.
The cgi script sends an autorespond email to the employee showing the results, but lists every item whether it was clicked or not! This makes it hard to find which items were requested. Example:
Butyl-Gloves =
Face-Shield =
Fore-arm-Protection = Yes
Goggles =
Leather-Gloves =
Safety-Glasses =
-end example-
How do I get it to just print the items ordered? In the example above, that woud be For-arm-Protection only.
And to take it one step forward. If someone ordered the first and last item, I wouldn't want any spaces between the items. It should look like this:
Butyl-Gloves = Yes
Safety-Glasses = Yes
I'm good with html, css, and just learning PHP now. Learning about If then statements and loops, but this cgi is way over my head.
I assume the part that needs to be changed is in this section of the script:
Any help would be greatly appreciated!
sub write_data
Not sure if this next part has anything to do with it?
sub decode_vars
Example:
HTML:
<input name="Butyl-Gloves" id="Butyl-Gloves" type="checkbox" value="yes">
<label><strong>Butyl Gloves</strong></label><br />
<input name="Face-Shield" id="Face-Shield" type="checkbox" value="yes">
<label><strong>Face Shield</strong></label><br />
<input name="Fire-Extinguisher-2.5Lb" id="Fire-Extinguisher-2.5Lb" type="checkbox" value="yes">
<label><strong>Fire Extinguisher (2-1/2LB)</strong></label><br />
<input name="Fore-arm-Protection" id="Fore-arm-Protectionb" type="checkbox" value="yes">
<label><strong>Fore-arm Protection</strong></label><br />
<input name="Goggles" id="Goggles" type="checkbox" value="yes">
<label><strong>Goggles</strong></label><br />
<input name="Leather-Gloves" id="Leather-Gloves" type="checkbox" value="yes">
<label><strong>Leather Gloves</strong></label><br />
<input name="Safety-Glasses" id="Safety-Glasses" type="checkbox" value="yes">
<label><strong>Safety Glasses</strong></label><br />
And so on, I have over 40 items.
The cgi script sends an autorespond email to the employee showing the results, but lists every item whether it was clicked or not! This makes it hard to find which items were requested. Example:
Butyl-Gloves =
Face-Shield =
Fore-arm-Protection = Yes
Goggles =
Leather-Gloves =
Safety-Glasses =
-end example-
How do I get it to just print the items ordered? In the example above, that woud be For-arm-Protection only.
And to take it one step forward. If someone ordered the first and last item, I wouldn't want any spaces between the items. It should look like this:
Butyl-Gloves = Yes
Safety-Glasses = Yes
I'm good with html, css, and just learning PHP now. Learning about If then statements and loops, but this cgi is way over my head.
I assume the part that needs to be changed is in this section of the script:
Any help would be greatly appreciated!
sub write_data
Perl:
{
if ($fields{'submit_by'} ne "")
{
if (&valid_address == 0)
{
&bad_email;
exit;
}
}
if ($fields{'submit_by'} ne "" && $fields{'emailfile'} ne "")
{
open (EMF,">>$fields{'emailfile'}");
print EMF "$fields{'submit_by'}\n";
close (EMF);
}
$the_date=localtime();
if ($fields{'submit_to'} ne "")
{
$msgtext="";
$msgtext .= "On $the_date,\n";
$msgtext .= "The following information was submitted:\n";
$msgtext .= "Host: $ENV{'REMOTE_ADDR'}\n";
}
if ($fields{'outputfile'} ne "")
{
&get_the_lock;
open(OUT_FILE,">>$fields{'outputfile'}");
}
foreach $to_print (@sortlist)
{
if ($fields{'outputfile'} ne "")
{ print OUT_FILE "$fields{$to_print}\|"; }
if ($fields{'submit_to'} ne "")
{ $msgtext .= "$to_print = $fields{$to_print}\n"; }
}
if ($fields{'outputfile'} ne "")
{
print OUT_FILE "$the_date\|\n";
close(OUT_FILE);
&drop_the_lock;
}
if ($fields{'submit_to'} ne "")
{
$mailresult=&sendmail($fields{submit_by}, $fields{submit_by}, $fields{submit_to}, $SMTP_SERVER, $fields{form_id}, $msgtext);
if ($mailresult ne "1")
{print "Content-type: text/html\n\n";
print "MAIL NOT SENT. SMTP ERROR: $mailcodes{'$mailresult'}\n";
exit
}
}
if ($fields{'cc_to'} ne "")
{
$mailresult=&sendmail($fields{submit_by}, $fields{submit_by}, $fields{cc_to}, $SMTP_SERVER, $fields{form_id}, $msgtext);
}
}
Not sure if this next part has anything to do with it?
sub decode_vars
Perl:
{
$i=0;
read(STDIN,$temp,$ENV{'CONTENT_LENGTH'});
@pairs=split(/&/,$temp);
foreach $item(@pairs)
{
($key,$content)=split(/=/,$item,2);
$content=~tr/+/ /;
$content=~s/%(..)/pack("c",hex($1))/ge;
$content=~s/\t/ /g;
$fields{$key}=$content;
if ($key eq "data_order")
{
$content=~s/ //g;
@sortlist=split(/,/,$content);
}
if ($key eq "required")
{
$content=~s/ //g;
@mandatory=split(/,/,$content);
}
}
if (
( ($fields{automessage}=~ /^([-\/\w.]+)$/ || $fields{automessage} eq "") &&
($fields{countfile}=~ /^([-\/\w.]+)$/ || $fields{countfile} eq "") &&
($fields{emailfile}=~ /^([-\/\w.]+)$/ || $fields{emailfile} eq "") &&
($fields{outputfile}=~ /^([-\/\w.]+)$/ || $fields{outputfile} eq "") )
&&
( (substr($fields{automessage},0,1) ne "/") &&
(substr($fields{countfile},0,1) ne "/") &&
(substr($fields{emailfile},0,1) ne "/") &&
(substr($fields{outputfile},0,1) ne "/") )
)
{$donothing=0;}
else
{
print "Content-type: text/html\n\n sorry, invalid characters...\n";
exit;
}
}