Actually, looking at this a bit closer, your second form is making a
call against db.recurso which changes your formkey and makes web2py
think you are tampering with the form when you try to submit the first
form. If I were you and wanted to make this really easy, I would make
sure I am running web2py 1.56.2 or higher and use the new crud tools.
For example:
Model:
db=SQLDB('sqlite://storage.db')
from gluon.tools import *
crud = Crud(globals(),db)
db.define_table('recurso',
SQLField('nombre','string',length=100,notnull=True))
db.recurso.nombre.requires=[IS_NOT_IN_DB
(db,'recurso.nombre'),IS_NOT_EMPTY()]
db.define_table('objetivo',
SQLField('descripcion','string',length=100,notnull=True, requires=
[IS_NOT_IN_DB(db,'objetivo.descripcion'),IS_NOT_EMPTY()]))
db.define_table('rec_obj',
SQLField('recurso',db.recurso),
SQLField('objetivo',db.objetivo))
db.rec_obj.recurso.requires=IS_IN_DB(db,'recurso.id')
db.rec_obj.objetivo.requires=IS_IN_DB(db,'objetivo.id')
Controller:
def index():
records=db(db.recurso.id==11).select()
form=crud.update(db.recurso, records[0], next='index')
form3=crud.create(db.rec_obj)
return dict(form1=form,form3=form3)
This will work quite well for this. If you don't want to do it this
way you could also make your initial form submit to a different action
although that is technically not a good practice. Does this help at
all?
-Jason
On Feb 13, 12:41 pm, vamaq <[email protected]> wrote:
> Hi everybody,
>
> I'm having a problem with a multiple form page. When I submit the
> first form (called form) I get the "user is tampering with form" error
> at the trace.
>
> The model is:
>
> db=SQLDB('sqlite://storage.db')
>
> db.define_table('recurso',
> SQLField('nombre','string',length=100,notnull=True))
> db.recurso.nombre.requires=[IS_NOT_IN_DB
> (db,'recurso.nombre'),IS_NOT_EMPTY()]
>
> db.define_table('objetivo',
> SQLField('descripcion','string',length=100,notnull=True, requires=
> [IS_NOT_IN_DB(db,'objetivo.descripcion'),IS_NOT_EMPTY()]))
>
> db.define_table('rec_obj',
> SQLField('recurso',db.recurso),
> SQLField('objetivo',db.objetivo))
> db.rec_obj.recurso.requires=IS_IN_DB(db,'recurso.id')
> db.rec_obj.objetivo.requires=IS_IN_DB(db,'objetivo.id')
>
> The controller is:
>
> def index():
>
> records=db(db.recurso.id==11).select()
>
> form=SQLFORM(db.recurso,records[0],deletable=True)
> form3=SQLFORM(db.rec_obj)
>
> form.accepts(request.vars,session,formname='myform1')
> form3.accepts(request.vars,session,formname='myform2')
>
> if form.errors: response.flash='Form has Errors'
> if form3.errors: response.flash='Form has Errors'
>
> return dict(form1=form,form3=form3)
>
> I will appreciate any guidance.
> Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" 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
-~----------~----~----~----~------~----~------~--~---