I have an HTML form. When the form is submitted, a jQuery code is executed to append an array of objects before data is sent to the server. Each object contains information retrieved outside the form.
<form method="post" id="formID" action="test.php" accept-charset="utf-8">
<!-- form inputs -->
</form>
$('#formID').submit(function() {
var form = $(this);
$('.file').each(function(index) {
var filedata = {
name: $(this).find('.name').text(),
ordernum: index,
size: $(this).find('.size').text()
};
form.append('<input type="hidden" name="filedata[]" value="' + filedata + '"/>');
});
});
My goal would be to retrieve these information on server side. Unfortunately, when I output $_POST
data, I only get a generic Object
data.
echo '<pre>';
print_r($_POST['filedata']);
echo '</pre>';
/* output */
Array
(
[0] => [object Object]
[1] => [object Object]
)
Is there a way to send an array of objects when submitting a form to server without using AJAX requests?