It appears that when you double click a submit button, the browser sends 
the post request twice, but it decides to ignore the response to the first 
request. web2py processes the first request and sends the redirect 
response, but the browser ignores it because of the second request. web2py 
also receives the second request, but because the form was already 
submitted once with it's unique _formkey, the form is not accepted and 
instead the index page is simply served again with an empty form. So, 
web2py should be preventing double submission of the form data (i.e., you 
shouldn't be getting duplicate records in the db), but the redirect is 
being ignored by the browser.

I'm not sure there is much web2py can do about this on the server side, but 
a common approach on the client side is to use Javascript to disable the 
submit button immediately after it has been clicked (so it cannot be double 
clicked). You could do that with a jQuery event handler on the page or by 
adding an onclick attribute to the submit button. Maybe web2py forms should 
do this by default.

Anthony

On Wednesday, May 2, 2012 5:55:30 PM UTC-4, Bruce Wade wrote:
>
> Hi,
>
> We have a form for buying products, the form generated has the _formkey 
> when clicking the submit button quick it does look like it doesn't submit 
> however it still runs all the code in the accepted method and if you go to 
> another page you can see that it really has completed the order.
>
> if ucashmethod.process(formname='ucash').accepted:
>   #this code is ran and the form is submitted even if 
>   redirect(URL('products','index')) # This is not ran at the end if you 
> double click the submit button fast.
>
> This has caused a major problem with double submittal of a 
> form. Primary because the person doesn't think the form is submitted 
> because it keeps them on the same page. 
> -- 
> -- 
> Regards,
> Bruce Wade
> http://ca.linkedin.com/in/brucelwade
> http://www.wadecybertech.com
> http://www.fittraineronline.com - Fitness Personal Trainers Online
> http://www.warplydesigned.com
>
>  

Reply via email to