How to run custom JavaScript immediately before form is submitted

Created by Phil Kurth, Modified on Fri, 01 Jul 2022 at 09:59 AM by Phil Kurth

Submission steps provide a way to intercept a form submission and run custom JavaScript immediately before. This is useful if you perhaps want to fire tracking events or implement something that requires some JavaScript-based handling before the payload is sent to the server. 


acf.addAction( "af/form/setup", function( form ) {
    af.addSubmissionStep( form, 10, function( callback ) {
        
        // Add your custom JS code here...

        // Invoke the callback to allow the next submission step to fire. If this is not called, the form won't submit and any submission handlers with a later priority won't be invoked. 
        callback();
    });
});


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article