Skip to content

Commit c7ff43a

Browse files
luizbillsk1sul1
authored andcommitted
Prevent multiple form submissions by disabling handler when submit is in progress
1 parent 17427e8 commit c7ff43a

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

assets/scripts/wplf-form.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ window.wplf = {
88
submitHandler: function (e) {
99
var form = e.target;
1010
var data = new FormData(form);
11+
12+
// prevent submitting the form again when a submission is already in progress
13+
if (form.classList.contains('sending')) {
14+
e.preventDefault();
15+
return;
16+
}
1117

1218
// Pass language if it exists.
1319
ajax_object.lang && data.append('lang', ajax_object.lang);
@@ -28,7 +34,7 @@ window.wplf = {
2834
return response.text();
2935
}).then(function(response) {
3036
response = JSON.parse(response);
31-
37+
3238
if( 'success' in response ) {
3339
// show success message if one exists
3440
var success = document.createElement("p");
@@ -145,4 +151,4 @@ window.wplf = {
145151
document.addEventListener('DOMContentLoaded', function () {
146152
initialize(dependencies, main);
147153
});
148-
}());
154+
}());

0 commit comments

Comments
 (0)