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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tstimple
Forum Commoner
Posts: 53
Joined: Wed Jan 21, 2004 10:12 pm

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

Post 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
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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 />';
     }
}
tstimple
Forum Commoner
Posts: 53
Joined: Wed Jan 21, 2004 10:12 pm

Post by tstimple »

THANKS!
Post Reply