replace if by_id_form.accepts(request.vars, session):
with if by_id_form.accepts(request.vars, session, formname='one'): if you use multiple forms they must have names and different names. On Sep 14, 12:56 pm, Thadeus Burgess <[email protected]> wrote: > I am having a problem when I declare two SQLFORMs and display them on the > same page. > > When inputing information, when the the submit button of either gets > clicked, the page refreshes and the data is not inserted into the database > and my response.flash does not show. > > If you click the submit button again, it will then insert into the database > correctly and show response.flash. It will continue to work until you visit > the page again with no post data. > > Is this a bug in specifying default=request.vars.varname in my > SQLFORM.factory? > > def add_tank(): > by_id_form = SQLFORM.factory( > SQLField("tank_id", default=request.vars.tank_id), # place the > previous entry into form, so if there are errors you don't have to retype > ) > by_url_form = SQLFORM.factory( > SQLField("tank_url", requires=[IS_URL()], > default=request.vars.tank_url), # place the previous entry into form, so if > there are errors you don't have to retype > ) > > if request.vars.tank_id: > if by_id_form.accepts(request.vars, session): > try: > tank_id = by_id_form.vars.tank_id > int(tank_id) # if its an integer, will throw exception > > if db(db.booty.tank_id == tank_id).select(): > by_id_form.errors.tank_id = "This tank has already been > added" > else: > id_booty = db.booty.insert(tank_id=tank_id) > response.flash = "Tank Added %s" % (tank_id) > by_id_form = SQLFORM.factory(SQLField("tank_id")) # > clear the form so that new data can be entered > except: > by_id_form.errors.tank_id = "Tank ID must be a number!" > > if request.vars.tank_url: > if by_url_form.accepts(request.vars, session): > tank_id = substring_between(by_url_form.vars.tank_url, > 'userEnvironmentId=', '&') > if tank_id == "INVALID": > by_url_form.errors.tank_url = "Not a valid url, does not > contain userEnvironmentId" > else: > if db(db.booty.tank_id == tank_id).select(): > by_url_form.errors.tank_url = "This tank has already > been added" > else: > id_booty = db.booty.insert(tank_id=tank_id) > response.flash = "Tank Added %s" % (tank_id) > by_url_form = SQLFORM.factory(SQLField("tank_url", > requires=[IS_URL()]))# clear the form so that new data can be entered > > return dict(by_url_form=by_url_form, by_id_form=by_id_form) > > -Thadeus > > http://thadeusb.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py-users" 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 -~----------~----~----~----~------~----~------~--~---

