Skip to content Skip to sidebar Skip to footer

How To Prevent Double Submit With Form Validation

I have been researching this problem for the last day or so. I am trying to prevent the user from double clicking on the submit button for my django project and submitting the for

Solution 1:

You can change the button type to button, and add a class to the form when it is initially submitted. If the class is present then do not submit the form. This prevents disabling the button.

See the below example using jQuery. Note that this assumes your validation is preventing the form from being submitted.

$("#status").click(function() {
    if(!$("form").hasClass("submitted")){
      $("form").addClass("submitted");
      $("form").submit();
    }
});
<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><formaction=""><inputtype="text"/><buttonid="status"type="button"value="Submitted">Submit</button></form>

Post a Comment for "How To Prevent Double Submit With Form Validation"