On Tuesday, April 22, 2014 5:52:42 PM UTC-4, Sharon Correll wrote:
>
> On Monday, April 21, 2014 5:30:40 PM UTC-5, Anthony wrote:
>>
>> ...when you create and process the form, its formkey goes into a list in 
>> the session...
>>
>
> Um, create and process are two different things. :-) After finally 
> figuring out how to see what's going on, I realize that it is the process() 
> method that makes this happen. For some reason I expected it to be the 
> creation method - maybe because it is surprising and unintuitive to me that 
> you are required call a process method before the form has even been 
> displayed! (I had set up my code that way because that's how the tutorial 
> does it, but I would never think to do it that way if it were just up to 
> me.)
>

The form is self-submitting (i.e., submits to the same action that 
generated it), so the same code runs when the form is created and when it 
is submitted. SQLFORM(...) defines the structure of the form, and 
form.process() then does one of two things -- (1) if no form data have been 
posted, it simply generates and adds the formname and formkey hidden 
fields, or (2) if form data have been posted, it checks the form key, 
performs validation, and (optionally) does a database insert/update.

Anyway, if you think that's confusing, try tracking the code to figure 
where/how the validation and error display is handled? :-)
 

> Okay, and now I am seeing that there is an attribute on the SQLFORM so I 
> can pull out the formkey and make the one in my own HTML match. (I had been 
> kludging it by looking through the SQLFORM and pulling them out of the 
> <input> structure, but that's far from ideal!)
>

 Yes, after calling .process(), you have form.formname and form.formkey, 
which you can use in custom HTML. You can also simply do:

{{=form.hidden_fields()}}

to include both hidden fields in the form.

Anthony

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to