Don't like ads? PRO users don't see any ads ;-)
Guest

Frank "HARRY" Puebló

By: a guest on Jun 14th, 2012  |  syntax: JavaScript  |  size: 0.78 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /**
  2.  * Block forms after first successful submit in
  3.  * order to prevent consecutive ones.
  4.  */
  5. $('form').each(function()
  6. {
  7.         // Reset all forms
  8.         $(this).data('submitted', 'no');
  9. });
  10.  
  11. // Submit listeners
  12. $('form').submit(function(e)
  13. {
  14.         if( ! $(this).attr('data-blockwith') || $(this).data('submitted') == 'no')
  15.         {
  16.                 // Let the form submit as per usual, but
  17.                 // disable the submit button and change its
  18.                 // text to the given "Submitting..." string.
  19.                 var s   = $(this).find('input[type=submit]');
  20.                 var msg = $(this).attr('data-blockwith');
  21.  
  22.                 $(s).val(msg);
  23.                 $(s).attr('disabled', true);
  24.  
  25.                 // Mark form as submitted
  26.                 $(this).data('submitted', 'yes');
  27.  
  28.                 // Let the form through
  29.                 return true;
  30.         }
  31.  
  32.         // Keep blocking the submits
  33.         e.preventDefault();
  34.         return false;
  35. });