Good questions. Answers below. > (in controller:) > def new_project(): > f = FORM(INPUT(_name = "project_title", _type = "text")) > if f.accepts(request.vars, session): > db.project.insert(dict(title = f.vars.title, description = > f.vars.description, user = session.user_id)) > redirect(URL(r = request, f = "list")) > else: > return dict(form = f) > > My question is: is there some way of doing: > ...db.insert.project(f.vars)... > ? > > I'd be awesome if I could make "user" a hidden field directly. That'd be like: > > ...f = SQLFORM(db.project, hidden = [db.project.user]) > f.vars.user = session.user_id... > > and then remove the db.project.insert line.
There are many ways you can do it: 1) the recommended way # list only the fields you want and pass the others directly to the vars f=SQLFORM(db.project,fields=['title']) f.vars.user=session.user_id 2) use a hidden field f=SQLFORM(db.project,fields=['title'],hidden=dict(user=session.user_id)) #but now the visitor can tamper with the hidden field in the form 3) Manually using ## vars has to be a dictionary (like form.vars) and must only contain valid fields, not including id. vars=form.vars vars.user=session.user_id db.project.insert(**vars) ## the ** unpacks the dictionary into named arguments --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to web2py@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---