Hi guys, I don't show up here too often because all the issues I find use 
to be solved here. Good job.

Today I was going nuts with one issue, and I would like to share my 
findings for other developer's shake.

I was generating a form with SQLFORM.factory:
form= SQLFORM.factory(...)

In the controller, I was creating a custom form for the view, something 
like:
custom_form= CAT(form.custom.begin,
                 ... custom fields...
                 form.custom.submit,
                 form.custom.end)

The custom_form displayed fine in the browser, but when I submitted the 
form, it wasn't accepted at:
if form.process().accepted:
   response.flash='Accepted'

Digging in the SQLFORM and FORM classes I learnt a lot about them, and 
finally I realized the origin of the problem:

   - form.process() requires a hidden field (*formkey*) with valid data for 
   security reasons. That field uses to be in form.custom.end
   - that field was missing in may custom_form
   - The reason was that when you create a form with SQLFORM.factory, 
   initially, there is no hidden *formkey* field in form.custom.end, just a 
   humble </form>
   - That *formkey* hidden field gets inserted in form.custom.end when you 
   call form.process()
   - That means that form.process() must be called before generating the 
   view, in order to have a formkey in form.custom.end. My failure was to try 
   tocreate custom_form = CAT() before calling form.process()
   - Should I have use {{=form.custom.end}} straight in the view, I would 
   have had no problem.
   - As I had quite a complex form, I preferred to have it generated in the 
   controller, and I just had to put the if form.process().accepted: before 
   generating programatically the custom_form and everything worked fine

Thanks a lot guys for this helpful group.
Best regards.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to