I would handle setting defaults in the above example by setting the default value on the fields before the SQLFORM call like this:
db.person.name.default = 'fieldvalue' -Jim On Mon, Jun 23, 2014 at 8:01 AM, Graham Ranson <g73...@gishpuppy.com> wrote: > Anthony <abastardi@...> writes: > > > If your going to use the web2py FORM or SQLFORM functionality, then the > same code both defines and processes the form, so self submission makes > sense. If you would rather build all of your form creation and processing > code from scratch, then sure, do whatever you want. Anthony > > That's the issue really - whether my design lends itself to self-submisson > and if not whether not using those features of web2py that are built around > self-submission rather reduce the benefits of using web2py at all. > It's not that I cannot see a way to use self-submission but there are then > oddities - well they seem so to me - I notice that the book says: > > "Pre-populating the form > > 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." > > and to use the example from a few lines earlier: > > def display_form(): > record = db.person(request.args(0)) or redirect(URL('index')) > url = URL('download') > link = URL('list_records', args='db') > form = SQLFORM(db.person, record, deletable=True, > upload=url, linkto=link) > > # pre-population would go here ?! > > if form.process().accepted: > response.flash = 'form accepted' > elif form.errors: > response.flash = 'form has errors' > return dict(form=form) > > in the example that I was thinking about that would involve a couple of DB > reads followed by the form.vars... assignments. Now if the same code is > then executed after submission how do these statements get handled ? I can > only suppose that re-executing the form=SQLFORM(...) has some magic in it, > but presumably not in the DB access and the form... assignments. > How does it deal with those ? > > I've been otherwise occupied in the past few days and still haven't > actually done any work wit web2py yet... > > 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.