Yes, you set the defaults for the table before the form=SQLFORM(...) statement. All you are doing is setting a default, you are not 'prepopulating' data.
Also, since web2py loads it's db.py on every request, the defaults you set in one request do not have an effect on subsequent requests. Also note what Anthony said earlier, you don't have to use the self-submission paradigm. You can force it to move to a different page on submission. -Jim On Tue, Jun 24, 2014 at 6:09 AM, Graham Ranson <g73...@gishpuppy.com> wrote: > 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 a topic in the > Google Groups "web2py-users" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/web2py/wbei89YDwL0/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > web2py+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- 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.