How to run Javascript after a form has been submitted successfully

Published in Convert Forms
Updated 16 May, 2020

There's a set of events on which you can bind your custom Javascript functionality and further extend Convert Forms to suit your specific needs. To execute your own script once the form is successfully submitted, you need to listen to the success event of the form. The example below, triggers an alert message every time the form #4 is successfully submitted.

document.addEventListener('DOMContentLoaded', function() {
    const form = document.querySelector("#cf_1");
    form.addEventListener("afterSubmit", function(event) {
        alert("Form successfully submitted. Thank you!");

The code above can be placed into the Custom Code option found under the Advanced panel of your form editing page. Do not forget to wrap the code with the <script> tag.

To read more details about the Convert Forms Javascript Events API, visit the Using the JavaScript Events API guide.