I have troubles with submitting a Form via Axios to Wordpress. Wordpress needs an "action" in the transmitted data and don't accept JSON as far as I know. So I created a URLSearchParams() object where I store my data, I want to send to wordpress. The Problem is, that I want to send an array of objects to wordpress via Axios, but I can't receive it in PHP.
var params = new URLSearchParams()
params.append('action', 'save_form')
params.append("x", x)
params.append("y", y)
persons.map((person, index) => {
params.append("myArr[]", JSON.stringify(myObj))
})
In PHP I want to receive the Objects like this, but because of URLSearchParams, the JSON is invalid...
foreach ($_POST["myArr"] as $myObjJson) {
// json_decode() fails
$myObj= json_decode($myObjJson);
}
How can I send the data from Javascript via Axios to my Wordpress-page and loop thru the array?