How do you handle submitting a form only once?

4

In a Method POST form, when I click the button twice it quickly executes the submission twice.

Solutions with javascript or with the spring framework.

    
asked by anonymous 14.09.2015 / 16:24

1 answer

10

Disable the button after the first click, because if the request delays the user will have the perception that the request was actually sent, and can not send another request.

$('form#id').submit( function( e ) {
  $( this ).children( 'input[type=submit]' ).attr( 'disabled', 'disabled' );
  e.preventDefault(); 
  return false;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><formid="id">
  <input type="submit"/>
</form>
    
14.09.2015 / 16:29