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

Hi all.
A quick quesiton. I have a form with about 100(+) for elements. There are mutlitple buttons which can trigger a submit event via javascript. (We currently are using javascript to catch for when a button has been pressed but we are still getting the double submit.) Also, I should not that the double submit only happens occasionally. Sometimes you hit the submit button and the expected behavior happens. Has anyone run into a form 'double' submitting on a button press when a user has only clicked a button once, and if so, how to fix?
Thanks
Zak
  • Comment on Netscrape and forms (Slightly Off Topic)

Replies are listed 'Best First'.
Re: Netscrape and forms (Slightly Off Topic)
by arturo (Vicar) on Apr 17, 2001 at 19:31 UTC

    Not so off-topic as you might think. Even if there's a problem in your Javascript somewhere (that stealth-submits on you or something), stopping double-submits is a good trick to have in your CGI programmin' toolkit.

    One way I might do it is to generate a unique ID for each form instance and add it as a hidden field to the form HTML; then you can check, in your form processing script, whether a form with that ID has already been submitted.

    HTH

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor

      Yeah, I was planning on doing that, but I was first wondering if there was a way we could control what the browser itself was sending... (I will be attempting to clean up the javascript code that we currently have anyways, but I was hoping there was a quick fix in Netscape land first.) Thanks Zak

        You could put an onsubmit attribute in your form tag and have the Javascript in that attribute redirect to a "processing" page (anything that gets you off the current page -- but it would have to be fast to prevent the problem). Or it could set a variable "submitted" that, if true, would disable further submissions.

        Philosophy can be made out of anything. Or less -- Jerry A. Fodor

Solution: Unexpected double inserts
by zakzebrowski (Curate) on May 04, 2001 at 18:49 UTC
    Hi all.
    This is relating to a previous node that I wrote about a double submit problem... I thought I would share the solution to what was happening. The way the form was coded, after the form was saved, the form user was then redirected to another page. On this redirection, sometimes the form was *sometimes* re-submitted again. Removing this redirection solved the problem. Just thought I would let everyone know.
    ----
    Zak