I'm building some form data, populating it with arrays, and sending it over POST, via:
let fd = new FormData();
for (section in this.data.choices) {
let key = section+(this.data.choices[section] instanceof Array ? '[]' : '');
fd.append(key, this.data.choices[section]);
}
fetch('?get=plan', {method: 'post', body: fd}) //...
Here's the structure of this.data.choices
:
{
"mode": "o7ew4xqybwt",
"packages": [
"wx2xv1cakbe"
],
"usertypes": [
"s"
],
"subjects": [
"bxn5g1igm4l",
"u1osgpv37fl",
"q2scwqb27k7",
"fl9riri0wpr"
]
}
However on the receiving side, in PHP, the arrays are arriving flattened. print_r($_POST) gives:
Array
(
[mode] => o7ew4xqybwt
[packages] => Array
(
[0] => wx2xv1cakbe
)
[usertypes] => Array
(
[0] => s
)
[subjects] => Array
(
[0] => bxn5g1igm4l,u1osgpv37fl,q2scwqb27k7,fl9riri0wpr
)
)
It's no doubt something simple I'm missing but any help would be appreciated.