Please anyone can help me to get form field array value and post them using ajax like form submit
From Fields like this :-
<input name="employment_Details[0][companyname]" >
<input name="employment_Details[0][companyemail]" >
<input name="employment_Details[0][companyphone]" >
<input name="employment_Details[1][companyname]" >
<input name="employment_Details[1][companyemail]" >
<input name="employment_Details[1][companyphone]" >
javascript goes here :-
<script type="text/javascript">
var formdata = /* form data goes here i mean form fields value*/'
Xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
}
};
xhttp.open("POST", "submit.php", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("form_submit=true&formdata=" + formdata);
<script>
php goes here :-
<?php
print_r($_POST['formdata']);
?>
Results : Expected results look like this
Array (
[0] => Array (
[companyname] => companyname goes here
[companyemail] => companyemail goes here
[companyphone] => companyphone goes here )
[1] => Array (
[companyname] => companyname goes here 1
[companyemail] => companyemail goes here 1
[companyphone] => companyphone goes here 1)
)