Form is submitted twice
← ejemplos
By default, after pressing the submit button, the plugin will validate fields and then submit the form if all fields are valid. If you use a custom submit handler, the form might be submitted more than one time.
This page will help you how to solve the issue.
Triggering the success.form.fv event
To prevent the plugin from submitting the form automatically, you can trigger the success.form.fv event:
You can use a custom submit handler like the following way:
Ensure that success.form.fv is triggered once
In some cases, even when using e.preventDefault()
inside the
success.form.fv
event handler, the form is still submitted twice. The issue
is caused by the fact that the success.form.fv
event is triggered more than
one time.
For example, in the following snippet, we initialize the plugin and handle the event when clicking on particular button:
As you see, the success.form.fv
event is handler inside the
addToCartButton
button click handler, the event will be triggered multiple
times from the second, third, ... time you click the button.
To solve this issue, you can remove the previous handler of success.form.fv
event by either destroying the plugin instance before creating new one:
or calling .off('success.form.fv')
: