You can append INPUT fields in the SQLFORM and perform manual insert
into the secondary tables after accepts.
Massimo
>>> from gluon.storage import Storage
>>> a=Storage()
>>> form=FORM(INPUT(_name='a',value='b'))
>>> form.accepts(a)
False
>>> print form
<form enctype="multipart/form-data" action="" method="post"><input
value="b" name="a" /><input value="default" type="hidden"
name="_formname" /></form>
You can do
form=FORM(TABLE(TR("Maps:", SELECT(_name='map_id',*[OPTION
(x.name,_value=x.id) for
x in db().select(db.map.ALL)])),
TR("", INPUT
(_type="submit",_value="Submit Map"))))
or simpler
form=SQLFORM(db.demo,fields=['map_id'])
In the second case you do not really needs validation. You can just user
if request.vars.map_id: .... use request.vars.map_id ...
Massimo
Massimo
def form_builder(labels=None,*a): return SQLFORM(SQDB
(None).define_table('mytable',*a),labels=labels)
def new_demo():
form=form_builder(SQLField('map_id',requires=IS_IN_DB
(db,'map.id','%(map_name)s')),
SQLField
('bomb_id',requires=IS_IN_DB(db,'bomb.id','%(btype)s')),
SQLField
('league_id',requires=IS_IN_DB(db,'league.id','%(league_name)s')),
SQLField
('team1',requires=IS_IN_DB(db,'team.id','%(team)s')),
SQLField
('team2',requires=IS_IN_DB(db,'team.id','%(team)s')))
if form.accepts(request.vars, session):
demo_id=db.demo.insert(map_id=form.vars.map_id,
bomb_id=form.vars.bomb_id,
league_id=form.vars.league_id,
demo_date=form.vars.date)
db.teamdemo.insert(demo_id=demo_id, teams_id=form.vars.team1)
db.teamdemo.insert(demo_id=demo_id, teams_id=form.vars.team2)
response.flash='Successfully uploaded a new demo!'
return dict(form=form)
Please tell us this about a game and we should not worry about the
use of the word bomb in here.
Massimo
def form_builder(labels=None,*a): return SQLFORM(SQLDB(None).define_table('mytable',*a),labels=labels)