Robert Hanson Robert Hanson - 5 months ago 17
HTML Question

Getting All $_POST From Multiple Select Value

I have this HTML code :

<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>


and to make user able to select more than one items, I'm using this jQuery plugin : http://harvesthq.github.com/chosen/

but, once it submitted... the PHP script only able to retrieve one of
$_POST['cars']
value. the last one. how to make PHP to be able to retrieve ALL of it?

Answer

I've found the answer...

<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>

and in the PHP part :

$cars = $_POST['cars'];
print_r ($cars);