I'm trying to submit a guest entry by building a javascript array of objects to mimic a form submission and submit using ajax. I've managed to successfully submit the entry with just a title but when trying to add Matrix/Super Table rows I'm having no luck.
I've looked here https://github.com/engram-design/SuperTable/wiki/Updating-a-Super-Table-field-from-a-front-end-form to get ideas for how this should work.
Super table block handle is answers
and the Super Table field I'm trying to submit is a plain text field with the handle question
.
My current code is:
$('#submitQuiz').on('click', function (e) {
e.preventDefault();
var testEntrySubmission = [
{
name: 'action',
value: 'guestEntries/saveEntry'
},
{
name: 'sectionId',
value: '5'
},
{
name: 'enabled',
value: '1'
},
{
name: 'redirect',
value: '/'
},
{
name: 'title',
value: 'user name'
},
{
name: 'answers[new1][fields][question]',
value: 'fingers crossed'
}
];
$.post('http://mywebsite.dev/', testEntrySubmission, function(response) {
if (response.success) {
console.log('success')
} else {
// response.error will be an object containing any validation errors that occurred, indexed by field name
// e.g. response.error.fromName => ['From Name is required']
alert('An error occurred. Please try again.');
}
});
});
fields
. So, youranswers[new1][fields][question]
should probably befields[answers][new1][fields][question]
. You can find an example of a front-end Matrix fields input structure here: straightupcraft.com/articles/…