I'll try and keep this short.
I have a form who's input fields (54 of them) are auto filled with data from a database. The ID of each input field is assigned with an ID using a PHP while loop. The user can edit the values and click submit. When the form is submitted, the data is passed to an array in jquery. I want to be able to pass that array from ajax to PHP via POST.
Form/submit page
$settings = array();
$counter = 0;
if(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_assoc($result)) {
$settings[$counter] = $row['value'];
echo "<tr>
<td>" . $row[$settings] . "</td>
<td><input type=\"text\" id=\"" . $counter . "\" value=\""
. $settings[$counter] . "\"></td>";
counter++;
}
}
mysqli_close($svr_link);
jQuery script (inside of the form/submit page)
$('#update').click(function(event) {
event.preventDefault();
var settings = [];
for (i=0; i<55; i++) {
settings[i] = $('#' + i).val();
}
$.ajax({
type: "POST",
url: "pages/post.php",
data: {settings:settings},
success: function(data) {
$('#message').html(data);
}
});
});
My question is:
Did I properly set up that data array in the ajax call?
How do I pull and deal with the data array in the post.php file?
Let me know if I omitted something relevant
$_POSTarray if passed correctly.print_r($_POST)in your to see what you have. You may want to think about converting the array to JSON before you send it, then decode the JSON on the PHP side for parsing.