Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting All $_POST From Multiple Select Value

Tags:

html

post

php

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?

like image 999
Saint Robson Avatar asked Oct 28 '12 16:10

Saint Robson


1 Answers

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);
like image 168
Saint Robson Avatar answered Oct 10 '22 15:10

Saint Robson