Doubled Form Submit

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Doubled Form Submit

jrick
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
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Doubled Form Submit

Esteban A. Maringolo
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 <[hidden email]>:

> 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
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Doubled Form Submit

Philippe Marschall
In reply to this post by jrick
On Tue, Apr 14, 2015 at 9:50 PM, J.F. Rick <[hidden email]> 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
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Doubled Form Submit

jrick
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 <[hidden email]> wrote:
On Tue, Apr 14, 2015 at 9:50 PM, J.F. Rick <[hidden email]> 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
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Doubled Form Submit

HilaireFernandes
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
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Doubled Form Submit

jrick
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 <[hidden email]> 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
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Doubled Form Submit

HilaireFernandes
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

--
Dr. Geo - http://drgeo.eu
iStoa - http://istoa.drgeo.eu

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside