One-Click Processing
By Randal L. Schwartz
One problem that seems to plague many Web programmers is how to achieve "one click" processing. No, I'm not talking about A
mazon's patented technology. I'm talking about circumventing that annoyance that occurs when a user clicks on a form's submit
button two or three times before a response is returned to the browser.
This is no big deal if the request is idempotent: that is, if a repeated request generates a consistent result, and each in
dividual request doesn't change the state of the world incrementally. However, many form submissions do intend to change the s
tate of the world somehow. For example, a shopping cart form might have a "buy this item" button, and multiple clicks might en
d up filling the cart with many copies of an item when the customer only wanted one. A survey form might return multiple votes
from a single participant. Or, multiple copies of a message might appear in a guestbook or chat room.
The communities in which I participate frequently offer solutions to this problem that involve JavaScript. No offense to th
e JavaScript coders, but more people than ever before are disabling browser scripting these days, thanks to the repeated CERT
warnings of security holesnot to mention those evil sites with pop-up advertising windows. Some companies are even insta
lling firewalls that strip the JavaScript at the corporate gatewayso it isn't even a choice for the user to "please enab
le JavaScript," in many cases.
But luckily, there's a simple server-side solution. Simply generate the form with a unique serial number embedded in a hidd
en field, and record that number in a lightweight server-side database.