Rails double submit -> double post -> duplicate data

Hi,

     We are encountering occasions where users post twice or more a form, basically we have detected two situations:
     a) The user push twice enter
     b) The user push double click on button "save" or "submit"

     We consider that this becomes a problem when creating (because we duplicate data) and we think that in some context it could become a security issue (like posting twice a payment), so we like to know How do you approach it?

     Our approaches to the problem:
     a) JavaScript implementation like "<form onSubmit="doublePostCheck()"> and only returning true the first time
         -> Problems: different navigators (firefox, safari....),
     b) Token / Flag validation, base on a hidden variable in the form, and validation of a unique token/server for post in the server
         -> Problems: how do you handle errors... do you save the first register and raise and error for the second?
         -> Where should we implemented in the controller "create"? Can it be in the class ApplicationController?
     c) Hash of the data in the post, and checking if last hash is different than the new one
         -> Problems: how do you handle errors... do you save the first register and raise and error for the second? We can't duplicate data if we need it
         -> Where should we implemented in the controller "create"? Can it be in the class ApplicationController?

     Thanks in advanced

Hi,

We are encountering occasions where users post twice or more a form, basically we have detected two situations:

a) The user push twice enter

b) The user push double click on button "save" or "submit"

Simplest solution we’ve done before is disabling the button on submit. this should work on all browsers.

Hi,

   We are encountering occasions where users post twice or more a form, basically we have detected two situations:
   a) The user push twice enter
   b) The user push double click on button "save" or "submit"

Simplest solution we've done before is disabling the button on submit. this should work on all browsers.

<%= f.submit 'Save', :disable_with => 'Saving...' %>

Nice and simple, and in the newer Rails, unobtrusive, too.

Walter

Hi,

     Works perfectly!

     Thanks a lot.

El 29/06/2011 13:57, Walter Lee Davis escribi�: