
Frank "HARRY" Puebló
By: a guest on
Jun 14th, 2012 | syntax:
JavaScript | size: 0.78 KB | hits: 19 | expires: Never
/**
* Block forms after first successful submit in
* order to prevent consecutive ones.
*/
$('form').each(function()
{
// Reset all forms
$(this).data('submitted', 'no');
});
// Submit listeners
$('form').submit(function(e)
{
if( ! $(this).attr('data-blockwith') || $(this).data('submitted') == 'no')
{
// Let the form submit as per usual, but
// disable the submit button and change its
// text to the given "Submitting..." string.
var s = $(this).find('input[type=submit]');
var msg = $(this).attr('data-blockwith');
$(s).val(msg);
$(s).attr('disabled', true);
// Mark form as submitted
$(this).data('submitted', 'yes');
// Let the form through
return true;
}
// Keep blocking the submits
e.preventDefault();
return false;
});