I have a form on a page, sometimes users can double-click the button to submit the form ...
The form is a
@using (Ajax.BeginForm(...))
{
}
How can I prevent this from happening?
I have a form on a page, sometimes users can double-click the button to submit the form ...
The form is a
@using (Ajax.BeginForm(...))
{
}
How can I prevent this from happening?
The simplest way is, via JavaScript, to detect that the form was submitted and to disable the submit button.
Example (with jQuery):
$('input[type=submit]').click(function(botao) { $(botao).prop('disabled', true); });
But this only works on the client side. For better usability it is better to use something more appropriate such as replacing a button with a "loading" or something. The example is just a quick fix .
If the question is not merely usability, but the validity of the form, you can mark your action with the
You can prevent this situation by doing this for example:
<form onsubmit="if(typeof fSub !== 'undefined') return false; fSub = true;">
Note : You can declare the variable
fSub
globally to avoid type validation.
Anyway, validation has always to be done on the server side to prevent attacks. It is bad practice to only validate on one side.