This is a really strange problem. I've got a form with a couple of fields, of which one of them is a multi select that looks like this:
<select name="age_group[]" multiple="multiple">
// options
</select>
When posting to the server, the key of the multi select in the $_POST
array looks like this:
age_group[
Why did the closing bracket got stripped? Also, the field is not saved as an array, but a string for some reason. When console.log()
the object I send to the server with jQuery, it all looks okay, and that very field is indeed an array.
POST header:
POST /ajax.php HTTP/1.1
Host: ds.local
Connection: keep-alive
Content-Length: 188
Accept: application/json, text/javascript, /; q=0.01
Origin: http://ds.local
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) > Chrome/29.0.1547.66 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Referer: http://ds.local/
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Cookie: PHPSESSID=9bniv5i558oslo6ne4ev59hdp6
POST data, human-readable
action: search
entity: DrugStats
data[name]:
data[substance]:
data[atc_code]:
data[year]: n/a
data[gender]: n/a
data[age_group[]][]: 3
data[county]: n/a
POST data, encoded
action=search&entity=DrugStats&data%5Bname%5D=&data%5Bsubstance%5D=&data%5Batc_code%5D=&data%5Byear%5D=n%2Fa&data%5Bgender%5D=n%2Fa&data%5Bage_group%5B%5D%5D%5B%5D=3&data%5Bcounty%5D=n%2Fa
Processing code
$.ajax({
url: 'ajax.php',
type: 'post',
dataType: 'json',
data: {
'action': 'search',
'entity': $(entity).data('entity'),
'data': data,
'page': page
},
success: function(data) {
// code
},
complete: function() {
// code
}
});