On Aug 14, 2009, at 4:31 PM, Jonathan Lundell wrote: > > I've got a table with two fields, an account name and a user id. > They're both required. > > I want something like this: > > naform = SQLFORM(db.acct, fields=['acct_name'], > hidden=dict(user_id=auth.user.id)) > if naform.accepts(request.vars, session): > response.flash = 'Account %s created' % request.vars.acct_name > elif naform.errors: > response.flash = 'Account not created' > > where the user will fill in the account name, and the form will > provide the user id. But of course the logic doesn't see a hidden > input as a table field, so naform.accepts() fails because user_id is > missing. > > OTOH, if I include user_id in fields, then it gets displayed, which is > not what I want either.
OK, answering my own question (and asking another below)... Prepopulating user_id does the right thing. Good. This isn't 100% clear from the prepopulation section of the manual, but I gave it a shot anyway. > > (Also, the missing field raises an exception; is that expected?) This was apparently because I had required=True, but no requires=IS_NOT_EMPTY(). Does that mean that an exception handler is needed for required and other database/DAL-level validations? If so, the manual could be clearer on the subject, and perhaps give some examples. But my new question is: after a successful SQLFORM.accepts, where do I find the id of the newly inserted record? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---

