Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-07-2004, 03:08 PM   PM User | #1
jacobcane
New to the CF scene

 
Join Date: Oct 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
jacobcane is an unknown quantity at this point
multiple select box and php handler

<select multiple size="8" name="activities" tabindex="6">
<option value="item one">item one</option>
<option value="item two">item two</option>
</select>

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....es_imagination

Thanks,

Jared
jacobcane is offline   Reply With Quote
Old 10-07-2004, 08:23 PM   PM User | #2
sad69
Senior Coder

 
Join Date: Feb 2004
Posts: 1,206
Thanks: 0
Thanked 0 Times in 0 Posts
sad69 is an unknown quantity at this point
I think you need to name it activities[]:
http://www.onlinetools.org/tricks/us...ple_select.php

Then you can loop through the various selected options.

Hope that helps,
Sadiq.
sad69 is offline   Reply With Quote
Old 10-07-2004, 09:15 PM   PM User | #3
jacobcane
New to the CF scene

 
Join Date: Oct 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
jacobcane is an unknown quantity at this point
how do I get this in the message

This is what I have so far based on doing what you suggested.

$activities=$_POST['activities'];
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?
jacobcane is offline   Reply With Quote
Old 10-07-2004, 09:31 PM   PM User | #4
sad69
Senior Coder

 
Join Date: Feb 2004
Posts: 1,206
Thanks: 0
Thanked 0 Times in 0 Posts
sad69 is an unknown quantity at this point
At this point, if you executed that script, I'd suspect it would print out:
Code:
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:
PHP Code:
$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:
PHP Code:
$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:
PHP Code:
$message .= "Activities: " implode(','$activities) . "\n\n"
Hope that helps,
Sadiq.
sad69 is offline   Reply With Quote
Old 10-07-2004, 10:26 PM   PM User | #5
jacobcane
New to the CF scene

 
Join Date: Oct 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
jacobcane is an unknown quantity at this point
Thanks

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.
jacobcane is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:02 AM.


Advertisement
Log in to turn off these ads.