Home › Forums › General Issues › Frontend form – post via ajax? › Reply To: Frontend form – post via ajax?
I think I found a better way. So in 5.7.13 on line 13386 of /assets/js/acf-input.js there is some new logic that checks if the submit event has already bee prevented. This is why things stopped working. In the examples above we are setting preventDefault()
for the submit event.
Looking further in acf-input.js onSubmit we can see there are a few lines to run the form validation. That validation also eventually runs acf.doAction('submit', this.$el);
when validation is successful.
I could not find a way to get around the new logic in acf-input.js onSubmit so I still keep the preventDefault() on the submit event. But then run the validation method to submit the form. Something like this:
$(document).on('submit', '.acf-form', function(e) {
e.preventDefault();
});
$('.save').on('click', function(event) {
if ($('.acf-form').length > 0) {
var valid = acf.validateForm({
form: $('.acf-form'),
event: acf.get('originalEvent')
});
}
});
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.