Page 1 of 1

preventing form double-submits - the plot thickens

Posted: Mon Mar 05, 2007 6:20 pm
by titaniumdoughnut
I know this isn't strictly PHP, but I figure someone will know the answer anyway.

I have a load of HTML forms, and I don't want double-submits, so I did the old button-turns-grey-after-you-click-it technique.

Code: Select all

<input type="submit" value="Sign up!" onclick="this.disabled = true;form.submit()">
I had to add the form.submit() bit because Safari wasn't actually submitting for some reason.

Now, here's the problem. A lot of users click back and change something when a form doesn't work because they didn't fill it out properly. The buttons are still grey when I go back. Is there a way to ungrey them when the user goes back to the page? This is rather perplexing, because it doesn't seem like a load event would even be called.

Maybe I'm just doing this wrong? I'd rather not do checking on the server-side, for various reasons.

Posted: Mon Mar 05, 2007 6:31 pm
by feyd
Why not simply provide a one-time use token for the form to submit?

Posted: Mon Mar 05, 2007 6:35 pm
by titaniumdoughnut
It just gets far too icky to keep track of tokens. The site is chock-full of submits, for everything from contributing content to logging in, tagging people, editing profiles, etc. Double-submits aren't the end of the world, so I don't NEED that kind of protection, and it gets really annoying dealing with tokens everywhere.

Unless there's some simple way I'm not thinking of.

Anyways, I know I've seen the grey-button trick work. I just need to figure out what I'm doing wrong.

Posted: Mon Mar 05, 2007 8:48 pm
by JAB Creations
You could switch the input button with a different element if the submit has been successful the first time. I like how Newegg makes the button say "processing.." so you don't accidentally double click the submit button. It's usually a problem with less savvy computer users who think they have to double click everything. I've seen people do it on power buttons! :lol:

Posted: Tue Mar 06, 2007 11:45 am
by titaniumdoughnut
Ah, yes. I like switching the text of the button to say "processing..."

Now, see... my problem is that any switch I do will stay in effect if the user reaches the next page, changes their mind, and clicks back. Pages aren't reset when you go back to them. They stay in the state they were left in. I need the button to return to its default clickable friendly state when you go back to its page.