Hi, This must be a well-known problem: you click multiple times on a form button, and multiple requests are send to the server. On many websites they ask you not to click on the "confirm purchase" button twice, because otherwise you'll be charged twice. Of course, browsers are to blame for this fault. I can't believe Internet Explorer and Netscape are both faulty at this (on Windows platform), but that's the sad reality. (What the heck where these programmers thinking when they made the form requests non-blocking?!!) Anyway, how can one handle the problem from the server side? Session management is an obvious candidate. Every time you receive a request, you set a busy flag, and dump all the following requests, until the first request is properly finished. But this has two problems: (1) You'll see on your browser the response to your last request, not to your first request. (2) If you use RESPONSE.redirect(), your session is locked up. Of course I can go down into the transaction manager level of Zope and do things from there. But I'd like to know how other people handle the multiple click problem. Is there any easy way out?! regards, Hung Jung ________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
Hung Jung Lu wrote:
This must be a well-known problem: you click multiple times on a form button, and multiple requests are send to the server. On many websites they ask you not to click on the "confirm purchase" button twice, because otherwise you'll be charged twice.
I've heard a suggestion I like a lot: send a hidden field in the form with a random but discernably unique value. When handling the form submission, before performing any other processing check whether that random value has already been copied to a small, persistent list. If the value is not there yet, add it and continue processing. But if the value is found, either stop the processing abruptly or somehow attach to the thread which is doing the processing and return its contents when it's finished. Note that you should not use ZODB persistence to store the list because each thread gets an independent view of the object database. The values should stay in the list for a few seconds beyond the end of the transaction, so you'll have to implement a basic garbage collection scheme. Shane
One site I have seen uses javascript on the client side: you get a dialog box that pops up on-click, tells you to only click once. Since the dialog is modal, if you did click twice it (did whatever your platform does when you have a modal dialog box up, eg beeps at you). (yes, of course, it'd be nice to have a solution requiring javascript, but I bet you that the people dumb enough to double click the submit button are the people with javascript on... =) jim -- Jim Hebert http://www.cosource.com/ jim@cosource.com The cooperative market for open source software "Well actually I was considering opening a market in flying pigs. Mostly because it would be more practical...." -- Alan Cox
participants (3)
-
Hung Jung Lu -
Jim Hebert -
Shane Hathaway