I have a form which I get the data from with new FormData(form)
. I'm having trouble getting my HTML arrays to properly pass over to PHP. I'm using vanilla JS and for example, in jQuery, using serializeArray()
would have serialized my HTML into something PHP understands. But now with JSON.stringify, it seems to ignore HTML arrays completely and I get this:
{"postData[0][val]":"1"}
passed over to PHP, where I would expect
{"postData": ["0": ["val": "1"]]}
My HTML:
<select name="postData[0][val]">
<option value="1">nothing</option>
<option value="2">boy</option>
<option value="3">girl</option>
</select>
<input name="postData[0][val2]" type='number'>
My Javascript:
const formData = new FormData(form).entries();
let postData = {};
for (var pair of formData) {
postData[pair[0]] = pair[1];
}
fetch(`${base}events/play/${event_id}`, {method: 'post', body: JSON.stringify(postData)})
I am properly reading the input in PHP.