how to prevent multiple email submissions

Asked

Viewed 812 times

1

Currently, my form sends the same email several times if the user clicks more than once on Ubmit. How do I stop this? I tried with these two variations of Cód, but it didn’t 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;
});
  • I got it from this Cód:

3 answers

2

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

Here what you need is a flag (flag) that prevents Ubmit from working until ajax returns. It has already been discussed other(s) question(s). What you lack here is to implement this and activate again in the return of ajax.

If the button is inside a formcan use as 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 inside the ajax:

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

0

I believe that if by clicking on Ubmit, you can redirect the user to another page, or refresh this page. This will prevent the user from sending the same email several times.

I hope it helps you.

-2


I had searched a lot, but I couldn’t find the answer. I got it with this code:

$("form").submit(function() {
    $(this).submit(function() {
        return false;
    });
    return true;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.