×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Online order form to only print items ordered

Online order form to only print items ordered

Online order form to only print items ordered

(OP)
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:

CODE --> 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

CODE --> 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

CODE --> 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;
     }
} 

RE: Online order form to only print items ordered

Hi

I would try to add the highlighted piece :

CODE --> sub write_data ( fragment )

foreach $to_print (@sortlist)
    {
      if ($fields{'outputfile'} ne "")
       { print OUT_FILE "$fields{$to_print}\|"; }
      if ($fields{'submit_to'} ne "" && $fields{$to_print} ne "")
       { $msgtext .= "$to_print = $fields{$to_print}\n"; }
    } 

Feherke.
feherke.github.io

RE: Online order form to only print items ordered

(OP)
OMG, I can't believe that is all that was needed! It worked!

Thank you so much. Are you able to explain how that works?

I assume it means any fields that are Not null.

Scott

RE: Online order form to only print items ordered

Hi

Yes, the %fields hash contains the checkbox data as checkbox name - value pairs. Then the loop processes each entry having the checkbox name in the $to_print variable, so the matching value can be accessed as $fields{$to_print}. As the value can be either "yes" or "" and you not want those with "", the condition just avoids those being appended to the mail body.

Feherke.
feherke.github.io

RE: Online order form to only print items ordered

(OP)
Thanks again!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close