how to prevent multiple submissions from an email form

1

Currently, my form sends the same email several times, in case the user clicks more than once on the submit. How can I prevent this? I tried with these two variations of the code, but it did not work.

$("#bt-enviar").on('click', function() {
    $(this).attr('disabled','true');
    $(this).css('cursor', 'default');
});

and

desab=0;    

if(desab == 1){
    $('#bt-enviar').attr('disabled','true');
    $('#bt-enviar').css('cursor', 'default');   
}

$("#bt-enviar").on('click', function() {
    desab=1;
});
    
asked by anonymous 22.08.2014 / 16:08

3 answers

-2

I had searched a lot, but could not find the answer. I got this code:

$("form").submit(function() {
    $(this).submit(function() {
        return false;
    });
    return true;
}
    
22.08.2014 / 16:16
2

I assume that you are sending via ajax, otherwise the problem would not arise.

Here you need a flag that prevents the submit from working until ajax returns. We have already discussed in other question (s) . What you're missing here is implementing that and re-enabling it in the ajax return.

If the button is within a form you can use it as it had, and for example, pointer events via class:

CSS

.bloqueia {
    pointer-events: none;
}

JavaScript / jQuery

$("form").submit(function(){
    $(this).addClass('bloqueia'); // ou somente o botão específico
}

and within ajax:

success: function(resp){
    // ...
    $("form").removeClass('bloqueia');
}
    
22.08.2014 / 18:37
0

I believe that if you click submit, you can redirect the user to another page, or refresh this page. This will prevent the user from sending the same e-mail several times.

I hope this helps you.

    
22.08.2014 / 16:16