You are welcome. Just a way of giving back so much help received from this 
group.
Best regards.

El lunes, 9 de mayo de 2016, 1:48:34 (UTC+2), Michael Beller escribió:
>
> Thanks Carlos!  I just came across this and your post helped me.
>
> On Friday, March 11, 2016 at 5:09:50 AM UTC-8, Carlos Kitu wrote:
>>
>> 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 sake.
>>
>> 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 my 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 
>>    to create 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 programatically generating 
>>    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