I am sending data to Ninja forms plugin to save in the WP, based on the example of how to send data from the frontend, that I could see on the Ninja form docs. I have implemented that on my backend side built with laravel/php:
$url = $this->postUrl . '/wp-admin/admin-ajax.php';
$client = new Client();
$response = $client->request('POST', $url, [
'form_params' => [
'security' => $this->getNonce(),
'action' => 'nf_ajax_submit',
'formData' => $request->formData,
]
]);
The formData looks like this:
{
"id":"1",
"fields":[
{"id":"1","value":"My Name"},
{"id": "2","value":"[email protected]"},
{"id":"3","value":"some message"}
]
}
Where id is an id of that ninja form in WP in my case Contact form, and each object in the fields array represents a field in the form. Id of that object is an id of that field.In my case id 1 is an id of name field, and id 2 is an id of email field, while id 3 is an id of message field. The data is being saved normally to message and email field as you can see on the image below, but not to the name field.
On checking the WP DB postmeta table I could see that fields are being saved as:
post_id | meta_key | meta_value
341 field_2 [email protected]
341 field_3 some message
341 field_
So, the problem is that the name field is being saved as only field_ with no value, why is there a problem when the other fields are being saved as they should?
I have also tried with sending the data with key value pairs like this:
{
"id":"1",
"fields":[
{"key":"name","value":"My Name"},
{"key": "email","value":"[email protected]"},
{"key":"message","value":"some message"}
]
}
But, then the message field is not being save. I have even tried the combination of having id for message field and key for name field, but then email field was not being saved. What am I doing wrong here?
