Page 1 of 1

Form field allows multiple choices...HOW to pass variables?

Posted: Thu Apr 08, 2004 9:10 pm
by tstimple
I have a form that has a list field that needs to allow the user to make multiple selections. This form action calls a PHP page.

for example...

Code: Select all

<select name="options" size="5" multiple>
	   <option value="dp">ABS</option>
	   <option value="x>">CD Player</option>
	   <option value="Tm">Climate Control</option>
	   <option value="CU">Cruise Control</option>
	   <option value="b^">Moon Roof</option>

       </select>
If (on the PHP page) I use

Code: Select all

<?php
$options=$_POST['options'];
echo $options;

?>
Only the LAST one of the choices is echoed.
How do I pass ALL the choices as variables to my PHP page??

--Tim

Posted: Thu Apr 08, 2004 9:13 pm
by markl999
In the form use <select name="options[]"
and in the PHP bit use:

Code: Select all

if(!empty($_POST['options'])){
    foreach($_POST['options'] as $option){
        echo $option.'<br />';
     }
}

Posted: Thu Apr 08, 2004 9:40 pm
by tstimple
THANKS!