Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Oct 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #3
    New to the CF scene
    Join Date
    Oct 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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?

  • #4
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #5
    New to the CF scene
    Join Date
    Oct 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •