I have two selection forms in one html page (see below), each with two
submit buttons, one to "update" a selected database item, and another
to select the item (i.e. store it in a session database) -- the code
for "multiple submit buttons" in one form was found in a web2py
thread. The first form works fine, but the second form after
submission (select or update) is processed by the action(s) of the
first form... I guess it probably has to do with the same "action"
name used in both forms, but I don't know whether it's related to the
_name, _id or "this.form.<action>.value" aspect, or to a combination
of these... Help appreciated! Thanks.
def process_A():
"""
Single form for A objects with multiple submit buttons (update and
select)
that trigger one submit function with different parameters
"""
o = < options list for A objects >
form=FORM(SELECT(*o, _name="aid"),
INPUT(_type='hidden',_name='action',_id='action',_value='undefined'),
INPUT(_type='button',_value='Update',_onclick='''this.form.action.value="1";this.form.submit();''',),
A(" "),
INPUT(_type='button',_value='Select',_onclick='''this.form.action.value="2";this.form.submit();''',),)
if form.accepts(request.vars):
if request.vars.action=='1':
< update an A obj >
elif request.vars.action=='2':
< select an A obj >
redirect(URL('index'))
else:
raise Exception("Invalid action")
#
return form
def process_B():
"""
Single form for B objects with multiple submit buttons (update and
select) that trigger one submit function
with different parameters.
"""
o = < options list for B objects >
form=FORM(SELECT(*o, _name="bid"),
INPUT(_type='hidden',_name='action',_id='action',_value='undefined'),
INPUT(_type='button',_value='Update',_onclick='''this.form.action.value="1";this.form.submit();''',),
A(" "),
INPUT(_type='button',_value='Select',_onclick='''this.form.action.value="2";this.form.submit();''',),)
if form.accepts(request.vars):
if request.vars.action=='1':
< update a B obj >
elif request.vars.action=='2':
< select a B obj >
redirect(URL('index'))
else:
raise Exception("Invalid action")
#
return form