I have the following ajax call to submit a Yii2 form:
var form = $("#purchase-order-form");
$.ajax({
url: form.attr('action'),
data: form.serialize(),
type: 'post',
success: function(data) {
$('#modal').modal('hide');
callNotify(data);
}
});
This works fine, however I have additional data that I need to pass along with the form's data. It is a string with json encoding, that I created calling JSON.stringify in an array created by me.
I tried to use .serializeArray() instead of .serialize() and push the additional content to the form, like this:
var form = $("#purchase-order-form");
var table-data = tableToJson('.products-table');
var data = form.serializeArray();
data.push({table: table});
$.ajax({
url: form.attr('action'),
data: data,
type: 'post',
success: function(data) {
$('#modal').modal('hide');
callNotify(data);
}
});
When I see the console, the content is at the end of the array, but in my Controller it is passed as undefined.
I think yii processes data that is not from the model before letting me load it.
How can I pass data along with the form while still being able to load the model using $model->load()?