Hello,
I have a SQLFORM.factory form that I need to prepopulate with some
data from a database.
id_nodo = request.args(0)
## I get the data from the database
nodo = db(db.node.id==id_nodo).select().first()
detalle = db(db.node_details.node_id==id_nodo).select().first()
##Now I need to prepolutate the fields title and body that I get from
the database
## title = nodo.title, body = detalle.body
form = SQLFORM.factory(db.node.title,db.node_details.body)
if form.accepts(request.vars,session):
response.flash='Form accepted'
return dict(form=form)
As I read on this thread
http://groups.google.es/group/web2py/browse_thread/thread/e2301b5cc3acd8dc/2a8ea5a2fba49bed?hl=es&lnk=gst&q=SQLForm+with+two+tables#2a8ea5a2fba49bed
somebody with the same problem as me did the following:
user = db((db.user.id == req_user_id) & (db.addr.user ==
req_user_id)).select()[0]
db.user.id.default = user.user.id
db.user.name.default = user.user.name
db.user.email.default = user.user.email
db.addr.city.default = user.addr.city
form =
SQLFORM.factory(db.user.name,db.user.rname,db.addr.city)
if form.accepts(request.vars, session):
# change the user data
if change_user_data(user):
user.user.update_record(name=form.vars.name) # <----
user.addr.update_record(city=form.vars.city) # <----
response.flash = 'form accepted'
else:
response.flash = 'form not accepted'
redirect(URL(r=request,f='index'))
I do not understand "if change_user_data(user):"
I have tried :
db.node.title.default = nodo.title
db.node_details.body = detalle.body
form = SQLFORM.factory(db.node.title,db.node_details.body)
if form.accepts(request.vars,session):
if change_node_data(node):
.......................................
......................................
but I get an execption ('global name change_node_data is not defined'.
Could anyone tell me how can I prepolutate the SQLFORM.factory form???
Why is the function change_user_data used in that example if is not
defined ????
Thanks in advance
--
Subscription settings: http://groups.google.com/group/web2py/subscribe?hl=en