Creating forms that don't resubmit in Kohana
30 Mar 2011
It is definitely one of my pet peeves: reloading a page only to see the "Confirm Form Resubmission" alert box that wants me to find my mouse and click on something that could have easily been prevented by the developer. This is 2011, for crying out loud, can't we have forms that don't suck?
The easiest solution to this problem is to load all posted form data into the session, and then reload the page internally. This clears the POST request while maintaining the submission and makes for happier users (and less headaches about the same comment submitted 14 times in a row).
Using Kohana's Session class makes it even simpler to remedy this ill of the internet. It really does not matter which driver you use, simply create a session and drop in the submission. The following controller action demonstrates the basics of this feature:
Now a simple view script with a form is all that is needed to complete this exercise. Although this is really just pseudo-code, I hope you get the idea.
To see this in action, fill out the comment section below, but leave the email input blank. The form will have errors, the messages will be displayed, the from will remain sticky (you other data will persist), but a refresh of the page will not show any resubmission warnings. Hopefully, this makes you a happier user. If not, let me know by commenting below, and feel free to ask any questions.