onWixFormSubmitted() not working

Hi everyone! I want to count how many times the form is submitted and print it in console. I copied the code from the API and edited it.
But it is not working and no error showed.
Here is my code

I’ll be appreciated to have your help! :slight_smile:

export function button1_click(event) {  
  console.log('clicked'); //the submit button is clicked
}

let counter = 0;
$w("#wixForms1").onWixFormSubmitted( (event) => {
  counter++;
  console.log(counter);
});

Hello from the Wix DevRel Team!

Try putting your onWixFormSubmitted() function call inside of the default onReady function like I did below:

let counter = 0;

$w.onReady(function () {

    $w("#wixForms1").onWixFormSubmitted( (event) => {
        counter++;
        console.log(counter);
    });
});

// export function button1_click(event) {  
//   console.log('clicked'); //the submit button is clicked
// }

This is working for me (and isn’t using the button1_click function at all, since Wix Forms handles that automatically)

Hope this helps!

Rob