Support

Account

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’)
    });
    }
    });
    `