Ryszard has asked for the wisdom of the Perl Monks concerning the following question:

I'm in the unfort situation where i have a web interface and a link that will execute a heavy and long query.

What I dont want is the user to double click the link, or click many times if the query doesnt return "fast enuff"

I've got some ideas for a locking mechanism, however I'm also after any idea's/experience others may have.

Replies are listed 'Best First'.
Re: CGI and locking
by rob_au (Abbot) on May 15, 2002 at 09:56 UTC
Re: CGI and locking
by zakb (Pilgrim) on May 15, 2002 at 12:05 UTC

    You can do this reasonably reliably client-side with Javascript too...

    I've written the below from memory, I have used something similar in the past for exactly this situation...

    <script language="javascript"> var submitCount = 0; function doSubmit() { if (submitCount == 0) { submitCount++; document.form1.submit(); } else { alert("Please wait, lengthy query executing..."); } } </script> ... <form name=...> ... <input type="button" onClick="doSubmit();"> </form> ...
    Update: andye beat me to it! This approach will only work if your clients have Javascript enabled.
Re: CGI and locking
by andye (Curate) on May 15, 2002 at 11:59 UTC
    One neat trick: use Javascript to deactivate the submit button on form submit.

    Obviously you need to do something on the server-side as well - because not everyone has Javascript switched on - but this method provides immediate feedback to (most) users and prevents them from even trying to double-submit.

    hth,
    andy.