Reputation: 4047
This supposedly simple but for some reason i cant figure out the value of a multiple select.
Here is an example:
<form action="" method="post">
<select name="cars" multiple="multiple">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
<input type="submit" />
</form>
Now in the php side i am trying to echo
or print_r($_POST['cars'])
;
However it doesnt print an array it only prints one value from the picked options.
Upvotes: 1
Views: 1373
Reputation: 1750
Change the name
of your <select>
to an array:
<form action="" method="post">
<!-- change cars to cars[] -->
<select name="cars[]" multiple="multiple">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
<input type="submit" />
</form>
Upvotes: 1