How to Prevent Users from Submitting a Form Twice

后端 未结 16 930
挽巷
挽巷 2020-12-01 06:59

when user click add button twice, from get submitted twice with same dat

相关标签:
16条回答
  • 2020-12-01 07:33

    You can add a class to your form and your submit button and use jquery:

    $(function() {
    
        // prevent the submit button to be pressed twice
        $(".createForm").submit(function() {
            $(this).find('.submit').attr('disabled', true);
            $(this).find('.submit').text('Sending, please wait...');
        });
    })

    0 讨论(0)
  • 2020-12-01 07:39

    You can disable the button after clicking or hide it.

    <input type="submit" name="btnADD" id="btnADD" value="ADD" onclick="disableButton(this)"/>
    

    js :

     function disableButton(button) {
         button.disabled = true;
         button.value = "submitting...."
         button.form.submit();
    }
    
    0 讨论(0)
  • 2020-12-01 07:40

    try out this code..

    <input type="submit" name="btnADD" id="btnADD" value="ADD" onclick="this.disabled=true;this.value='Sending, please wait...';this.form.submit();" />
    
    0 讨论(0)
  • 2020-12-01 07:40

    You can use JavaScript.

    Attach form.submit.disabled = true; to the onsubmit event of the form.

    A savvy user can circumvent it, but it should prevent 99% of users from submitting twice.

    0 讨论(0)
提交回复
热议问题