Jessica Mather Jessica Mather - 5 months ago 8
PHP Question

How can I get the values of a multiselect into an echo statement?

I am trying to get the values of a multiselect to be listed into a php email form. The variable is name="variable[] "

I don't know how to go about it, so any advice would be awesome

$message = "<html><head><title></title></head>
<body>
<p>Sentence".$_POST['somevarriable']."</p>
<p>Another Sentence". [I want to put an array here]."</p>
</body>
</html>";

Answer

Something like this? (Untested)

$message = "
    <html>
        <head><title></title></head>
        <body>
            <p>Sentence" .$_POST['somevarriable']. "</p>
            <p>Another Sentence "
    ;

    foreach ($_POST['variable'] as $selectedOption){
        $message .= $selectedOption . ' ';
    }

    $message .= "
            </p>
        </body>
    </html>
    ";

Reference:

How to get multiple selected values of select box in php?