C
C#4mo ago
Whiteboy

✅ Submit form just once, disabling the button breaks form submition

So i need to submit form just once and the submitions takes about 3-5s, how can i prevent user from spamming the button (it creates huge load on server if he spams 100cps) if i wrote simple JS to disable the button after clicking it doesn't submit the form
<form method="post" asp-page-handler="SubmitCode" asp-route-assignmentId="@Model.Assignment.AssignmentId">
<div align="center">
<textarea id="UserCode" name="UserCode" class="form-control" style="resize: vertical; width: 98%;" rows="20" placeholder="Enter your code here"></textarea>
</div>
<div style="margin-right: 1%; margin-bottom: 1%; margin-top: 1%" align="right">
<button id="SubmitCode" type="submit" name="action" value="SubmitCode" class="btn btn-primary" disabled>Submit</button>
</div>
</form>
<form method="post" asp-page-handler="SubmitCode" asp-route-assignmentId="@Model.Assignment.AssignmentId">
<div align="center">
<textarea id="UserCode" name="UserCode" class="form-control" style="resize: vertical; width: 98%;" rows="20" placeholder="Enter your code here"></textarea>
</div>
<div style="margin-right: 1%; margin-bottom: 1%; margin-top: 1%" align="right">
<button id="SubmitCode" type="submit" name="action" value="SubmitCode" class="btn btn-primary" disabled>Submit</button>
</div>
</form>
2 Replies
Angius
Angius4mo ago
Just use JS
let allowSubmit = true;
const form = document.getElementById('form-id');
form.addEventListener('submit', e => {
if (allowSubmit) {
form.submit();
allowSubmit = false;
} else {
e.preventDefault();
}
});
let allowSubmit = true;
const form = document.getElementById('form-id');
form.addEventListener('submit', e => {
if (allowSubmit) {
form.submit();
allowSubmit = false;
} else {
e.preventDefault();
}
});
Whiteboy
Whiteboy4mo ago
i've makde a button cover and it works jsut fine i won't bother messing witj js rn xd
Want results from more Discord servers?
Add your server
More Posts