form.accepts(...)
is not intended to read the received hidden fields and move them into
form.vars. The reason is security. Hidden fields can be tampered with.
So you have to explicitly move hidden fields from the request to the
form:form.vars.a = request.vars.a
"
So I think you do not have attr field in the table activity, do you?
If so, you should do something like that:
values=request.vars
del values['attr']
db(db.activity._id == request.vars['id']).update(**dict(values))
--I have used a form in a view and want to update a record after submit:View:{{=SQLFORM(db.activity, record = a.id, deletable = True, hidden=dict(attr='chgact'))}}controller:if (request.vars['attr'] == 'chgact') and (request.vars['delete_this_record'] != 'on'):db(db.activity._id == request.vars['id']).update(**dict(request.vars))I use the convention in the controller because is is described in the manual in chapter 6:The update of record with given id can be done with:
Inserting and updating from a dictionary
A common issue consists of needing to insert or update records in a table where the name of the table, the field to be updated, and the value for the field are all stored in variables. For example:
tablename
,fieldname
, andvalue
.The insert can be done using the following syntax:
db[tablename].insert(**{fieldname:value})
The update of record with given id can be done with:
db(db[tablename]._id==id).update(**{fieldname:value})
Notice we used
table._id
instead oftable.id
. In this way the query works even for tables with a field of type "id" which has a name other than "id".What is going wrong?
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+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.