Stop multiple submits for a html from

后端 未结 2 443
温柔的废话
温柔的废话 2021-01-29 11:03

So I\'ve google this problem, they all give the same code but it never works. I want to be able to only click on the button once so you can\'t spam click the button sending the

2条回答
  •  北海茫月
    2021-01-29 11:17

    You would need to make one of your required inputs enable the submit button - it arrives disabled - set by the init() function. I have done it for a textbox here to illustrate.

    You will need to set a value in your JavaScript for $hidden_input when the textbox is typed into - it should be 0 when the page loads but be set to 1 when it is ready to submit. You could set it up in different ways with the value being set in PHP as well. That depends exactly how you want it to perform.

    You should also set your form action to .

    
    
      
        
        
        
        
    
          
    Click to start a new submission

    You can use the value from the hidden input to block future submission -

     if (intval($_POST['hidden_input']) == 1){
      // skip your signup code
     }
    

    Bear in mind that this page is mostly dependent on JavaScript - just in case that may be an issue for those who don't like JavaScript dependency.

提交回复
热议问题