Reputation: 961
def test():
form = SQLFORM.factory(Field('cards', requires=IS_IN_DB(db, 'tbl_card.id', '%(name)s')))
form = SQLFORM.factory(Field('evo', requires=IS_IN_DB(db, 'tbl_evo.id', '%(evo_type)s', orderby=db.tbl_evo.id)))
return dict(form=form)
I want to be able to have multiple SQLFORMS in a single view. How would I do this from one controller function?
For my benefit, how would I call different functions (not named test()) to generate forms in the same view?
Upvotes: 1
Views: 3408
Reputation: 25536
First, your code doesn't process the forms, so you would need to call the .process()
method on each form. When you do that, you can specify a unique name for each form, which will enable web2py to tell them apart when submitted:
form1 = SQLFORM.factory(Field('cards',
requires=IS_IN_DB(db, 'tbl_card.id', '%(name)s')))
form1.process(formname='form1')
If you want to call separate functions to generate and process each form, you can put those functions in a model file or module and then call them from the test.html view. If you want to use AJAX, a better option is to put each form inside a component using LOAD()
:
{{=LOAD('default', 'myform1', ajax=True)}}
Upvotes: 2
Reputation: 3542
Have you looked at the manual, specifically:
Forms & Validators: Multiple forms per page
Upvotes: 3