Question

I am using the jQuery Validation Plugin. When I make more then one click on submit button, the alert of success message show me more then one time. How to prevent multiple clicks on submit button?

$(document).ready(function() {
    $('#contact-us').validate({
        rules: {
            cName: 'required',
            email: 'required',
            cText: 'required'
        },
        messages: {
            cName: '<?php echo $errorName; ?>',
            email: '<?php echo $errorEmail; ?>',
            cText: '<?php echo $errorComment; ?>'
        },
        submitHandler: function(form) {
            var formInput = $(this).serialize();
            $.post($(this).attr('action'), formInput, function(data){
                $('#contact-us').fadeOut('fast', function(){                   
                    $(this).before($('<p class="alert alert-success"><?php _e( 'Your message was sent successfully. Thanks!' ); ?></p>').fadeIn('fast'));
                });
            });
        }
    });
});
Was it helpful?

Solution

You can disable the submit button. Or you can replace the submit button with a "Processing..." text.

OTHER TIPS

You can also remove the onClick value of the button, or use event.preventDefault()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top