Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Processor not Sending Multiple-Select Fields 1

Status
Not open for further replies.

Spycat

MIS
Apr 21, 2006
6
US
Hello,

I am using a Perl script to process and send form input to an e-mail address.
It works nicely when only one selection can be made, but one of my fields ("Stores[]") requires that the respondant make 3 selections. What happens is the processor only sends out the 1st field it encounters and ignores the following two.
The php form I was using handled it fine. However the IT guys can't figure out how to install/configure php on the Windows server(!) and so here I am trying to come up with another solution (I am the web designer).

Here is a snippet of the HTML code. The multiple-selects are named "Stores[]"
Code:
<td>
                 <input type="checkbox" name="Stores[]" value="Gilroy" tabindex="11" />	
        </td>
         <td>
                 <span style="white-space:nowrap;">Gilroy Store<br />
				845 First Street<br />
	  			Gilroy 
	           </span>	
        </td>
        <td>
                  <input type='checkbox' name='Stores[]' value='Santa_Teresa' style="float:left;" tabindex="15" />
       </td>
        <td>
                 <span style="white-space:nowrap;">Santa Teresa Store <br />
				7098 Santa Teresa Blvd.<br /> 
		                San Jose</span>	
       </td>
        <td>
                <input type='checkbox' name='Stores[]' value='San_Carlos' style="float:left;" tabindex="19" />
       </td>
       <td>
                <span style="white-space:nowrap;">San Carlos Store<br />
				1691 W. San Carlos St.<br /> 
		                 San Jose 
                 </span>
       </td> 
        etc...
Here is a snippet of the Perl Script where I specify variables:
Code:
#Order in which fields should be shown in the email - list all fields here - this is CASE SENSITIVE
@field_order = ("FirstName","LastName","Email","Gender","Income","Age","Language","Stores[]");
#You can check required fields at the form using Javascript, or list them here for simple checking.
#@required_fields = ("NAME","EMAIL","PHONE");

#Fields output - These give human readable labels to the output fields.  Again, there should be one for each field.
$fields{"FirstName"} = "First Name";
$fields{"LastName"} = "Last Name";
$fields{"Email"} = "E-Mail Address";
$fields{"Gender"} = "Gender";
$fields{"Income"} = "Income Range";
$fields{"Age"} = "Age Range";
$fields{"Language"} = "Primary Language";
$fields{"Stores[]"} = "Favorite Stores";
Here is the part of the code that actually processes the input, and I am
sure, where the solution lies:
(I have specified NO required fields, since I already have a javascript that is doing that)
Code:
print $query->header;

#Check required Fields
my $field;

foreach $field (@required_fields) {
  if(!$query->param($field)) {
    print "<script>
      alert(\"Please supply the following information: $fields{$field}\"); 
		history.back();</script>";
    exit;
  }	
}

#Send out the email

    $smtp = Net::SMTP->new($mailhost);

    $smtp->mail($ENV{USER});
	foreach $r (@mail_to) {
    		$smtp->to($r);
	}
    $smtp->data();
    $smtp->datasend("From: $mail_from\n");
    $smtp->datasend("To: ".join(",",@mail_to)."\n");
    $smtp->datasend("Subject: $subject\n");
    $smtp->datasend("\n");
    $smtp->datasend("The following was submitted:\n\n");
    my $outline;
    foreach $f (@field_order) {
	$outline = sprintf("%30s: %s",$fields{$f},$query->param($f));
	$smtp->datasend($outline."\n");
    }
    $smtp->dataend();

    $smtp->quit;


#Send out a Confirmation email

if($confirmation_email_to =~ /\@/) {

    my $smtp = Net::SMTP->new($mailhost);

    $smtp->mail($ENV{USER});
    $smtp->to("$confirmation_email_to");

    $smtp->data();
    $smtp->datasend("From: $confirmation_email_from\n");
    $smtp->datasend("To: $confirmation_email_to\n");
    $smtp->datasend("Subject: $confirmation_subject\n");
    $smtp->datasend("\n");
    $smtp->datasend("$confirmation_body\n");
    $smtp->dataend();

    $smtp->quit;

}


print "<META HTTP-EQUIV=refresh content=\"0;URL=$thankyou_url\">\n";
Can anyone see an easy fix for this?
Also, if I am not pressing my luck, is there a simple way to have this processor ALSO write the form input to a comma-delimited file?
If not, no biggie on that one.

Thanks for all who respond

Rick
 
you have to get the multi-valued form field as a list, not a scalar:

my @foo = $query->param('Stores[]');


read the CGI.pm documentation and I'm sure you will figure it all out.


look for the "FETCHING THE VALUE OR VALUES OF A SINGLE NAMED PARAMETER:" section.
 
Hi Kevin,

Sorry for the X-Post, but desperate times...
I sincerely thank you for taking the time.
Here is what I have so far, but it is not sending me the "Stores" data.
I am unsure as to where to put the my @storelist = $query->param('Stores[]');
Code:
#Order in which fields should be shown in the email - list all fields here - this is CASE SENSITIVE
my @storelist = $query->param('Stores[]');
@field_order = ("FirstName","LastName","Email","Gender","Income","Age","Language","storelist");
#You can check required fields at the form using Javascript, or list them here for simple checking.
#@required_fields = ("NAME","EMAIL","PHONE");

#Fields output - These give human readable labels to the output fields.  Again, there should be one for each field.
$fields{"FirstName"} = "First Name";
$fields{"LastName"} = "Last Name";
$fields{"Email"} = "E-Mail Address";
$fields{"Gender"} = "Gender";
$fields{"Income"} = "Income Range";
$fields{"Age"} = "Age Range";
$fields{"Language"} = "Primary Language";
$fields{"storelist"} = "Favorite Stores";

I don't want to be a bother, but where exactly would I put it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top