Insert into with waiting time

0

I have a form that its action sends to a .php file that makes an insert in the database with the information passed by the form, and I already noticed that if I click twice as fast on the submit button it sends two records identical to the database, someone knows how I make a wait system for example if I send a record now to 00:41:27 I'll only be able to send another one 00:41:29 a 2-second timer, or by clicking on the submit button once it blocks so it does not send the same record twice.

    
asked by anonymous 05.11.2015 / 03:42

1 answer

4

You can disable the input with javascript:

function funcao (obj) {
  obj.disabled = true; // desabilita o input
  console.log("qualquer código dentro da função.");
};
<input type="submit" value="Teste1" onclick="this.disabled=true" />
<br />
<input type="submit" value="Teste2" onclick="funcao(this)" />

The funcao is only used in the click of Test2. Advantage that can run multiple codes in the same event, while Test1 is limited to just disabling the button.

Within funcao you can still use this code snippet:

setTimeout(function(){
    obj.disabled = false;
}, 3000)

This will make the button re-enable in 3 seconds.

    
05.11.2015 / 04:42