Anthony <abastardi@...> writes:

> 
> 
> It would probably help if you show some code, or at least explain in more 
detail an example where self submission is not possible or overly 
difficult. Note, your code can always distinguish between a form creation 
request and a form submission request by checking whether request.post_vars 
is None or whether request.env.http_method == "POST". As Jim suggested, if 
you are using SQLFORM, the easiest way to pre-populate is by setting field 
default values before form creation.Anthony
> 
> 
Well, I cannot show any code - because I haven't written any real stuff yet 
- and I cannot give an example of where self-submission could not work 
because I haven't gotten to that point, yet (if at all). As I said I'm just 
investigating but self-submission is one aspect of web2py that did stand 
out to my superficial run through its features.
My experience in web-type applications is of the 'single purpose code' 
type: one method assembles the data for the web page, from a database or 
some default values etc., and then 'returns' it to the web client; then an 
entirely separate method is the target for the subsequent HTML form 
submission, it receives the data and creates the necessary data structure 
(object or whatever) and populates it from the data on the POST, stores it 
in the DB etc. This has a complete separation of functions. 
And to some extent it is this lack of a clean separation that I find a 
problem in the self-submission case, perhaps more philosophically than 
practically, I'll agree.
But to return to the example I gave: I did quote from the book:

"It is always possible to pre-populate a form using the syntax:
form.vars.name = 'fieldvalue'

 Statements like the one above must be inserted after the form declaration
 and before the form is accepted, whether or not the field ("name" in the
 example) is explicitly visualized in the form."

but are you suggesting that it is better to populate the db.tablename 
object's defaults before the 'form=SQLFORM(...' statement ?
And I did suspect that there was some indicator used within the FORM object 
- you mention request.post_vars being None, so if there were any complex 
code to establish the pre-population values I should enclose that in a 
condition like:

if request.post_vars == None:
        #
        # put pre-population data acquisition here
        # including calls to other methods - if lengthy code
        #
form = SQLFORM(...

Sorry to go on so...

Graham





-- 
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