View Full Version : multiple select box and php handler

10-07-2004, 04:08 PM
<select multiple size="8" name="activities" tabindex="6">
<option value="item one">item one</option>
<option value="item two">item two</option>

On the form handler page which this form action goes to, I am sending an email using php. The part of the message that using the 'activities' variabler looks like this.

$message .= "Activities: " . $activities . "\n\n";

I have more options then what is show in the above example. But the problem I am have is that only the last option selected is showing up in the mail. I need to use some type of an array or something to hold and send all of the items selected in the email. I need some one to help me with this or at least give me some pointers in the right direction. The page that this is being used on is at: http://www.gettocostarica.com/index.php?page=packages_imagination



10-07-2004, 09:23 PM
I think you need to name it activities[]:

Then you can loop through the various selected options.

Hope that helps,

10-07-2004, 10:15 PM
This is what I have so far based on doing what you suggested.

if ($activities){
foreach ($activities as $a){echo 'You selected ',$a,'<br />';}

//Putting together the Mail Message to company
$message = "Invoice purchase from www.cncink.com";
$message .= "\nDate: ".date("m/d/Y, h:i A")."\n----------------------------------------\n";
$message .= "Name: " . $name . "\n";
$message .= "Email Address: " . $email . "\n";
$message .= "Number of People: " . $number_of_people . "\n\n";
$message .= "Phone: " . $phone . "\n\n";
$message .= "Arrival Date: " . $arrival_date . "\n\n";

$message .= "Activities: " . $activities . "\n\n";
//End of the message
$message .= "\n----------------------------------------\n";

How is I get this information into the message area?

10-07-2004, 10:31 PM
At this point, if you executed that script, I'd suspect it would print out:

Activities: Array

I'm guessing you know nothing about arrays...

All the activities are contained in the $activities array, so to get each activity you need to reference the element using its corresponding index:

$index = 0; //or any other number
$activity = $activities[$index];

To get ALL the values out of the array, which is what you seem to want, you have to loop through it:

$message .= "Activities: \n";
foreach ($activities as $index=>$activity) {
$message .= $activity."\n";

Or if you want all the activities on the same line, separated by a comma, you can use the implode() function:

$message .= "Activities: " . implode(',', $activities) . "\n\n";

Hope that helps,

10-07-2004, 11:26 PM
thank you for your help, it is working now. Send me your contact information to jared@cncink.com or you are interested in freelance php work in the future.