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

Am 18.11.2010 09:56 schrieb “Srikanth J.” [email protected]:


You received this message because you are subscribed to the Google G.
“Ruby on Rails: Talk” group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected][email protected]
.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.

Norbert M. wrote in post #962309:

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

Am 18.11.2010 09:56 schrieb “Srikanth J.” [email protected]:


You received this message because you are subscribed to the Google G.
“Ruby on Rails: Talk” group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to

[email protected][email protected]

.

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:

display the page. localhost/controller/display

def display



end

def save_details



redirect_to :action => “display”
end

So, when the first click of save button, the action “save_details” will
be called and redirected to the first action “display”. Now the reloaded
page is fresh, i.e the id is unique.

On Thu, Nov 18, 2010 at 12:58 AM, Norbert M.
[email protected] wrote:

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.

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

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:


Hassan S. ------------------------ [email protected]
twitter: @hassan

Norbert M. 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.

On Nov 18, 2010, at 9:25 AM, Hassan S. wrote:

entry

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 S. wrote in post #962339:

On Thu, Nov 18, 2010 at 12:58 AM, Norbert M.
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.