Stopping double clicking with Perl CGI

Smylers Smylers at
Thu May 22 15:45:43 BST 2008

Chris Jack writes:

> Thank for all the replies. My opinion of CGI has gone down as a result
> of the various discussions...

I don't think CGI (which is a protocol the web-server and your program
use to speak to each other) has anything to do with this.

> 1) If I disable the push button then run another perl script to
> process my results -> if I then push the back button the push button
> is still disabled on the first screen as I cannot pick up that the
> back button has been pressed.

Some sites manage to do something like this, for example when filling in
a YouGov survey:

* Submit the form to answer question i.
* In response the server sends the form for question i + 1.
* Press Back, hoping to return to question i.
* That page checks with the server, is told that question i has already
  been answered, and insists on presenting you question i + 1.

I haven't checked to see how they do it (and unfortunately you have to
create a YouGov account to see these pages; though presumably the
technique is used elsewhere as well).

Possibly it's just with HTTP headers marking pages as being
very-not-cachable, so that when I press 'Back' the browser asks the
server for the latest version of that page.  Or possibly there's some
JavaScript involved which forces it to 'phone home'.

> IMO, all of these are actually worse for my application than allowing
> double clicks.

Yes.  Whatever you do, you can't completely control the data that
clients may send at your server.  So you need for your program to be
robust enough that it will cope with any data sent at it.  The earlier
suggestion of embedding a hidden field with a unique number in each form
is a good one -- then your server can react appropriately if it
discovers a form being submitted multiple times.

> So I'm thinking that I could do 1 - but have a push button on the next
> screen to go back to the first screen. Still not what I would describe
> as good.

Indeed, re-implementing browser chrome is bad.

> Oh - and given that this seems like a pretty fundamental sort of
> issue, I am disappointed that my CGI Programming with Perl doesn't
> even mention it, let alone suggest a robust solution.

I haven't read that book, but I'm guessing it's because the book focuses
on CGI and Perl.  Possibly a JavaScripty book would cover this kind of

For many forms it isn't a problem: some are idepotent, such as search
queries; and for things like confirming purchase of items in a shopping
basket, after the first time you'll easily spot the condition because
the basket will be empty.


More information about the mailing list