Why do you need to redirect back to the same view to display the error? The 
normal way of doing this is basically what you currently have: if there is 
an error in the form in the POST, immediately redisplay the form.

I think the reason this is failing is because of the formkey technique used 
by web2py. When you auto-generate a form (as with SQLFORM), a random "form 
key" is generated and inserted into the form. The same key is also saved in 
the web2py server. When the form is submitted and web2py checks it with 
form.accepts, it first verifies that the submitted formkey is one that was 
previously generated by web2py. If the key is found, it is removed from the 
list of pending formkeys. If the key is not found, the form is reset. 

The point of this is to prevent people from accidentally submitting the same 
form twice (imagine accidentally clicking the submit button twice when 
submitting a credit card purchase). But I bet you're running into a case 
where you redirect and send the form vars, but the formkey is no longer 
valid (since it has already been generated and accepted once), so the form 
is reset after the redirect.

Long story short, regenerate the form in the same request if there is an 
error - don't redirect unless there's some reason for this that I'm not 
realizing.

Cheers,
Kevin

Reply via email to