I'm using Multiple Select with Groups and Multiple Select from http://harvesthq.github.com/chosen/
Does anyone know how to get the values of the submitted data using php?
$_POST['countries'];
does not work and only returns one of the selected items (not an array)
And here is the select tag name/id etc
<select name="countries" multiple="multiple" class="chzn-select" id="countries" tabindex="6" data-placeholder="Countries">
PS. I already checked Chosen Jquery Plugin - getting selected values but can't figure out what to do except for getting the value. Is there a straight forward method without using events to update a hidden field and submit data?
When you are posting multiple values using a <select>
you need to name it a way, it looks like an array
.
<select name="countries[]">
</select>
This should be the way. And upon POST
, the variable should be accessible as:
$_POST['countries'] = array(
[0] => 'India' , // First selected value
[1] => 'Indiana' , // Second
[2] => 'USA' // Third
);
// So...
echo $_POST['countries'][1];
// would print "Indiana"
Note: The values will be held in a standard, zero-indexed array