Skip to content

Commit 0cd8fc3

Browse files
authored
Block multiple form submits on application form. (#4452)
Fixes #4348 Before this js snippet it was possible on a slow network to post a application form multiple times by rapidly clicking the submit button multiple times. Would be neat to use aplinejs for this everywhere but it interfere with the current "unlockApplicationForm" feature that we use to block some spam.
1 parent 2fe3f17 commit 0cd8fc3

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

hypha/apply/funds/templates/funds/application_preview.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@
3838
</div>
3939
</form>
4040

41-
<form id="preview-form-edit" class="form application-form" action="{% url 'funds:submissions:edit' object.id %}">
41+
<form id="preview-form-edit" class="form application-form" action="{% url 'funds:submissions:edit' object.id %}" x-data="{ isFormSubmitting: false }" x-on:submit="isFormSubmitting = true">
4242
{% csrf_token %}
4343
</form>
4444

4545
<div class="form__group">
46-
<button class="button button--primary" form="preview-form-submit" name="submit" type="submit">{% trans "Submit for review" %}</button>
46+
<button class="button button--primary" form="preview-form-submit" name="submit" type="submit" :disabled="isFormSubmitting">{% trans "Submit for review" %}</button>
4747
<button class="button button--secondary" form="preview-form-edit">{% trans "Edit" %}</button>
4848
</div>
4949

hypha/static_src/javascript/application-form.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@
4949
// Remove the "no javascript" messages
5050
document.querySelector(".message-no-js").remove();
5151

52+
// Block multiple form submits.
53+
form.addEventListener("submit", function () {
54+
button.setAttribute("disabled", "disabled");
55+
});
56+
5257
const unlockApplicationForm = function () {
5358
form.setAttribute("action", "");
5459
button.removeAttribute("disabled");

0 commit comments

Comments
 (0)