I have generated a form, a number of the fields are multiple selects. The values are generated from a foreach (due to the required format):
echo '<select name="data[formdata]['.$question['PrPageQuestion']['ID'].']" id="formdata'.$question['PrPageQuestion']['ID'].'" multiple="multiple">';
foreach($contacts as $contact):
echo '<option value="'.$contact['PrDataContact']['ID'].'">'.$contact['PrDataContact']['Name'].' ('.$contact['PrDataContact']['Email'].')</option>';
endforeach;
echo '</select>';
However when i select multiple and submit the form, i run the debug only one value is being passed, not a string as expected.
The html output is:
<select name="data[formdata][2]" id="formdata2" multiple="multiple">
<option value="13">A Contact (a.contact@email.com)</option>
<option value="14">A. Nother-Contact (a.n.contact@email.com)</option>
<option value="15">A. New. Contact (anc@email.com)</option>
<option value="17">New Conti (new@conti.com)</option>
</select>
The output of var_dump is:
array(2) {
["_method"]=> string(4)
"POST" ["data"]=> array(1) {
["formdata"]=> array(8) {
//other data was here
[1]=> string(1) "1"
[2]=> string(2) "15"
[3]=> string(1) "4"
[4]=> string(0) ""
}
}
}
You need to add [ ] after the name to tell html that this is an array of values to be submitted
You should then get: