Skip to content

Commit d71a2c8

Browse files
authored
Merge pull request #6297 from WoltLab/6.2-form-builder-form-guard
Prevent multiple submits of FormBuilder forms
2 parents a1e3b7a + e18871c commit d71a2c8

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

com.woltlab.wcf/templates/shared_form.tpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,11 @@
8282
FormBuilderFieldDependencyManager.checkDependencies();
8383
});
8484
</script>
85+
86+
{if !$form->isAjax()}
87+
<script data-relocate="true">
88+
require(['WoltLabSuite/Core/Form/Builder/FormGuard'], ({ setup }) => {
89+
setup(document.getElementById('{unsafe:$form->getId()|encodeJS}'));
90+
});
91+
</script>
92+
{/if}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Prevents multiple submits of the same form by disabling the submit button.
3+
*
4+
* @author Marcel Werk
5+
* @copyright 2001-2025 WoltLab GmbH
6+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
7+
* @since 6.2
8+
*/
9+
10+
export function setup(form: HTMLFormElement) {
11+
form.addEventListener("submit", () => {
12+
form.querySelectorAll<HTMLInputElement>("input[type=submit]").forEach((button) => {
13+
button.disabled = true;
14+
});
15+
});
16+
}

wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/FormGuard.js

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)