[Seaside] Re: Doubled Form Submit

J.F. Rick self at je77.com
Fri Apr 24 15:37:36 UTC 2015


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 at 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 at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/seaside/attachments/20150424/69beb3f5/attachment.htm


More information about the seaside mailing list