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
Check these links: http://www.onlinetools.org/tricks/using_multiple_select.php and How to get multiple selected values of select box in php?
The select name should have square brackets at it's end, so it would be
name="countries[]"
Use print_r()
at the PHP code to see what was posted.
Use foreach()
to loop through the values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With