2

Im pretty new to php programing but im trying to pass the values from a multislect object im html to some code in PHP that will then email the listed people

However the vairable passed via post appears to only be the last item selected

How do you pass something as an array?

html code:

<li id="li_6" >
            <label class="description" for="Names[]">Employees who should be added to this charge code: (Hold CTRL to Multi Select)</label>
            Malav, Nancy, Filiz, CJ are added by default and not on the list
            <div>
                <select name="Names" multiple>  
                    <option value="[email protected]">Bi,Gilbert</option>
                    <option value="[email protected]">Bor,Jeff</option>
                    <option value="[email protected]">Bt,Ivan</option>
                    <option value="[email protected]">Caos,Sheryl</option>
                    <option value="[email protected]">Car,Raymond</option>
                    <option value="[email protected]">Cs,Dale</option>
                    <option value="[email protected]">Cles,Cathy</option>
                    <option value="[email protected]">Cl,Lori</option>
                    <option value="[email protected]">Cons,Renee</option>
                    <option value="[email protected]">ine,Cassandra</option>
                    <option value="[email protected]">Ctt,Pamela</option>
</select>
            </div> 
        </li>

Php Code:

<?php
// Read POST request params into global vars
    $from = "[email protected]";
    $title = $_POST[Title] ;
    $mname = $_POST[ManagerName];
    $memail = $_POST[ManagerEmail];
    **$names= $_POST['Names']; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<**
    $other = $_POST[element_4];

    print $email;
    $to = "[email protected]" + $memail;
    $message ="Title: $title \r\nManager: $mname\r\nManager email: $memail\r\n" ;
    $headers = "From: $from";
    $today = date("m/d/Y");
    $ok = @mail($to, $subject, $message, $headers);

    echo "Your email has been sent! Please confirm with Malav if you do not receive a confrimation email in 2 hours";
?>

3 Answers 3

10

To pass it in as an array of values, add square brackets to the name attribute of your select element..

<select name="names[]" multiple="multiple"> 

Then you can iterate over the values in php.

foreach ( $_POST['names'] as $selectedOption )
Sign up to request clarification or add additional context in comments.

Comments

1
foreach ($_POST['Names'] as $selectedOption)
    echo $selectedOption."\n";

Comments

0

when I use this:

foreach ( $_POST['names'] as $selectedOption )

and I insert in the database "$selectedOption" appear in the database this:

on

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.