Double click the submit button, submits form twice

Hi,

I have a form, When i click submit button twice, My form gets submitted twice, and 2 entries are saved.

But I need only 1 entry to be saved. Any idea on how to do it?

Hidden field wich unique ID. If the ID is submitted twice, omit the new entry

Norbert Melzer wrote in post #962309:

Hidden field wich unique ID. If the ID is submitted twice, omit the new entry

-- You received this message because you are subscribed to the Google Groups

"Ruby on Rails: Talk" group.

To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to

rubyonrails-talk+unsubscribe@googlegroups.com<rubyonrails-talk%2Bunsubscribe@googlegroups.com>

.

For more options, visit this group at

http://groups.google.com/group/rubyonrails-talk?hl=en.

Please try this. When the save functionality completed, you should redirect to the previous action, if you are not using the action both "Page Display" and "Save Process"

ex:

Norbert Melzer wrote in post #962309:

Hidden field wich unique ID. If the ID is submitted twice, omit the new entry

That did it. Thanks all for reply.

But suppose the user clicks submit, instantly recognizes an error in the information, hits stop, corrects the error, and clicks submit again?

If you discard the *second* submission, there is now a discrepancy between what the user intended and what you've stored. Uh-oh.

Might want to give that a little more thought :slight_smile:

Are you trying to trap a "bounce" here -- a double-click because of machine or user error that is being interpreted as two separate submit events? You can easily trap those by adding :disable_with => 'Saving...' to your button tag. Only the first click will be accepted, and the button will gray out and stop accepting input after that. Happens at the JavaScript level, so the response will be very nearly immediate.

Walter

Hassan Schroeder wrote in post #962339:

On Thu, Nov 18, 2010 at 12:58 AM, Norbert Melzer But suppose the user clicks submit, instantly recognizes an error in the information, hits stop, corrects the error, and clicks submit again?

If you discard the *second* submission, there is now a discrepancy between what the user intended and what you've stored. Uh-oh.

Besides fixing the double-submission problem in the view layer you might also want to add appropriate unique indexes to prevent the possibility of duplicates at the database level. Doing so will at lease ensure data integrity and prevent insert race conditions.