I have a form which contains multiple group fields.Which is posted via ajax on. Everything is okay.I just need to create an array to send it to the backend.I am using serializeArray().may be it is wrong form to send data.That's why i am geting error
<form method="post" id="tasks-multiform">
<div id="people-container">
<h3>Person 1:</h3>
<p>
<label>First name</label><br>
<input name="people[1][first_name]">
</p>
<p>
<label>Last name</label><br>
<input name="people[1][last_name]">
</p>
<p>
<label>Email</label><br>
<input name="people[1][email]">
</p>
<h3>Person 2:</h3>
<p>
<label>First name</label><br>
<input name="people[2][first_name]">
</p>
<p>
<label>Last name</label><br>
<input name="people[2][last_name]">
</p>
<p>
<label>Email</label><br>
<input name="people[2][email]">
</p>
</div>
<a href="javascript:;" id="add-new-person" class="add-new-person">Add! new person</a>
<p>
<input type="submit" value="Save">
</p>
</form>
Above is the form and data is posted via ajax.And below is jquery codes..avoid action
its wp backend function
jQuery(document).on('submit', '#tasks-multiform', function(e){
e.preventDefault();
var form = jQuery('form#tasks-multiform');
var data = form.serializeArray();
console.log(data);
jQuery.ajax({
type : 'post',
url : admin_ajax.ajax_url,
data : {
action : 'utasks',
tasksdata : data,
tasksnums : tasksnums,
},
beforeSend : function(){
jQuery('.tasksubmit').attr('disabled', 'disabled');
},
});
});
i wanted somethin like :
{"1"=>
{
"first_name"=>"",
"last_name"=>"",
"email"=>""
},
"2"=>
{
"first_name"=>"",
"last_name"=>"",
"email"=>""
}
}
But what i am getting:
{"1"=>
{
"[prople][1][first_name]"=>"",
},
"2"=>
{
"[prople][1][last_name]"=>"",
},
"3"=>
{
"[prople][1][email]"=>"",
},
"4"=>
{
"[prople][2][first_name]"=>"",
}
"5"=>
{
"[prople][2][last_name]"=>"",
}
"6"=>
{
"[prople][1][email]"=>""
}
}
How can i resolve this?