I've noticed that it happens occasionally that a user double clicks the form submit button, sending the form content to the server twice. Is there a standard way / pattern to avoid a post getting added twice?
Cheers,
Jeff
A javascript event handler to disable the submit button (and maybe form submission as well) once clicked.
Regards! Esteban A. Maringolo
2015-04-14 16:50 GMT-03:00 J.F. Rick self@je77.com:
I've noticed that it happens occasionally that a user double clicks the form submit button, sending the form content to the server twice. Is there a standard way / pattern to avoid a post getting added twice?
Cheers,
Jeff
seaside mailing list seaside@lists.squeakfoundation.org http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
On Tue, Apr 14, 2015 at 9:50 PM, J.F. Rick self@je77.com wrote:
I've noticed that it happens occasionally that a user double clicks the form submit button, sending the form content to the server twice. Is there a standard way / pattern to avoid a post getting added twice?
You could implement your own callback that is executed only once [1]
[1] https://code.google.com/p/seaside/issues/detail?id=157
Cheers Philippe
I ended up implementing the javascript event handler to disable the submit button (not too difficult). It seems crazy that a browser even allows for a form to be submitted multiple times. I once got into trouble because I was transferring money to my Paypal account and accidentally double clicked the submit button. It ended up processing the request twice and almost cost me an overdraft fee. It would be nice if seaside provided an elegant way to ensure that a form is only processed once.
Cheers,
Jeff
On Wed, Apr 15, 2015 at 4:02 AM Philippe Marschall < philippe.marschall@gmail.com> wrote:
On Tue, Apr 14, 2015 at 9:50 PM, J.F. Rick self@je77.com wrote:
I've noticed that it happens occasionally that a user double clicks the
form
submit button, sending the form content to the server twice. Is there a standard way / pattern to avoid a post getting added twice?
You could implement your own callback that is executed only once [1]
[1] https://code.google.com/p/seaside/issues/detail?id=157
Cheers Philippe _______________________________________________ seaside mailing list seaside@lists.squeakfoundation.org http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Hi,
So Paypal does not have this level of safty.. Can you share your implementation? It very likely be useful to the communnity the next time one wants to learn from it.
Thanks
Hilaire
Le 15/04/2015 19:09, J.F. Rick a écrit :
I ended up implementing the javascript event handler to disable the submit button (not too difficult). It seems crazy that a browser even allows for a form to be submitted multiple times. I once got into trouble because I was transferring money to my Paypal account and accidentally double clicked the submit button. It ended up processing the request twice and almost cost me an overdraft fee. It would be nice if seaside provided an elegant way to ensure that a form is only processed once.
Sure. Though it is mainly a client-side solution. Here is the Javascript function: // jQuery plugin to prevent double submission of forms jQuery.fn.preventDoubleSubmission = function() { $(this).on('submit',function(e){ var $form = $(this);
if ($form.data('submitted') === true) { // Previously submitted - don't submit again e.preventDefault(); } else { // Mark it so that the next submit can be ignored $form.data('submitted', true); } });
// Keep chainability return this; };
Then, here is how I used it in Seaside: (1) I give the form a unique ID (html nextId) and have that in a temporary variable id. (2) After the form has been added, I add the following to trigger the Javascript: html script: '$("#', id asString, '").preventDoubleSubmission;'.
What this does is that it overrides default behavior to only submit the form once. It would be much nicer if this were taken care of at the server-side (something like "html submitOnceForm" instead of "html form") as you can never count on the client side to behave properly.
Cheers,
Jeff
On Mon, Apr 20, 2015 at 5:05 AM Hilaire hilaire@drgeo.eu wrote:
Hi,
So Paypal does not have this level of safty.. Can you share your implementation? It very likely be useful to the communnity the next time one wants to learn from it.
Thanks
Hilaire
Le 15/04/2015 19:09, J.F. Rick a écrit :
I ended up implementing the javascript event handler to disable the submit button (not too difficult). It seems crazy that a browser even allows for a form to be submitted multiple times. I once got into trouble because I was transferring money to my Paypal account and accidentally double clicked the submit button. It ended up processing the request twice and almost cost me an overdraft fee. It would be nice if seaside provided an elegant way to ensure that a form is only processed once.
-- Dr. Geo - http://drgeo.eu iStoa - http://istoa.drgeo.eu
seaside mailing list seaside@lists.squeakfoundation.org http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Le 24/04/2015 17:37, J.F. Rick a écrit :
Sure. Though it is mainly a client-side solution. Here is the Javascript function:
Thanks to share.
Hilaire
seaside@lists.squeakfoundation.org