Home Forums General Issues Frontend form – post via ajax?


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) {
    $('.save').on('click', function(event) {
        if ($('.acf-form').length > 0) {
         	var valid = acf.validateForm({
    			form: $('.acf-form'),
    			event: acf.get('originalEvent')
Viewing 26 post (of 26 total)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.