3

do Codeigniter 3.0.0 preventing from double submit automatically or not? Is there any helper/library for this? I looked at form validation and form helper, but there is nothing about it.

Thank you very much.

lubik
  • 49
  • 3
  • 6
  • In my opinion, it would be a better user experience to handle it using JavaScript. Otherwise you would have to store a token that the form passes along and the php code has to check if that token has already been used and redirect to a "ooops already submitted page". Flag a js variable in the onsubmit of the form. Check that variable in the onsubmit as well and return false if it is true preventing the duplicate submit. – Paul Zepernick Jun 02 '15 at 15:27
  • 1
    Have a look at this answer. http://stackoverflow.com/questions/2830542/prevent-double-submission-of-forms-in-jquery It's a jQuery solution to your problem. – Craig Jun 02 '15 at 15:28
  • If javascript isn't an option that's the best answer yet http://stackoverflow.com/a/8165979/2498790 – Alex Aug 21 '15 at 07:22
  • Best answer ever: https://stackoverflow.com/questions/8165018/duplicate-data-insert-in-codeigniter – Marcelo Agimóvel Nov 30 '17 at 12:42

1 Answers1

0

No, CI 3 doesn't handle double form submission. What you have to do is to submit your page and redirect to another one after successfull submission.

Now, let's say your user clicks two or three times because maybe his mouse is not working right, or his connection is too slow... then you can also put a code in the form and if the form gets submitted then save that code with it's timestamp and prevent future submission for that code.

Periodically, with cron, you can erase saved form codes that are older than 1 minute or so.

Hope that helps.

Beto Aveiga
  • 3,466
  • 4
  • 27
  • 39