You are using a manual HTML form instead of {{=form}}. For an update form you need to include
1) <input type="hidden" name="id" value="{{=form.latest.id}}" 2) {{=form.hidden_field()}} for create 1) is not necessary. Errors are in form.errors (it is a dictionary). Because you are building the form manually, you need to display the errors where you want them. web2py does not build multi-table forms but you can create that manually using form_builder or the way you are doing it: > form=FORM(INPUT(_name="name"),INPUT(_name="description"),SELECT > (_name="type"),SELECT(_name="subtype"),INPUT(_name="priority"),INPUT > (_name="enabled"),INPUT(_type="submit",_value=T("Save"))) Notice that in the case below the form has no knowledge of the database. This means accept will only do validation for you. No more. Massimo On Dec 12, 8:23 am, Fran <francisb...@googlemail.com> wrote: > On Dec 11, 5:49 pm, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > 1) use your html instead of {{=form}} for but in the form include > > {{if form.errors.email:}}{{=form.errors.email}}{{pass}} > > {{=form.hidden_field()}} > > I'm trying to do the same kind of thing. > I tried using > form=SQLFORM(db.gis_layer) > However I am missing one of the hidden_fields that I need for T2 > conflict detection: > <Storage {'modified_on': 'must be YYYY-MM-DD HH:MM:SS!'}> > (Also, all errors are just getting reported in this ugly way in the > form.errors section & not against each field) > > If I don't have validation errors then I get this error when it > attempts to update the database: > File "C:\Bin\web2py\applications\sahana/controllers/gis.py", line > 184, in update_layer > if form.accepts(request.vars,session,keepvalues=True): > File "C:\Bin\web2py\gluon\sqlhtml.py", line 229, in accepts > raise SyntaxError, "user is tampering with form" > > So I tried using: > form=t2.update(db.gis_layer) > Then I don't get any error reporting at all (the form just resets if > there is 1). > > If I don't have validation errors then I get the same error when it > attempts to update the database: > File "C:\Bin\web2py\applications\sahana\modules\t2.py", line 457, in > update > if form.accepts(request.vars,session): > File "C:\Bin\web2py\gluon\sqlhtml.py", line 229, in accepts > raise SyntaxError, "user is tampering with form" > > I'm guessing that this is because I am building a form from multiple > tables. > This just isn't supported by either SQLFORM or T2 is it? > In which case I need to build my own CRUD...which is probably best > done by extending the T2 class, since I want to use some of it's > functionality. > > As a 1st go, I'm doing it within my Controller using plain old FORM: > form=FORM(INPUT(_name="name"),INPUT(_name="description"),SELECT > (_name="type"),SELECT(_name="subtype"),INPUT(_name="priority"),INPUT > (_name="enabled"),INPUT(_type="submit",_value=T("Save"))) > > However form.accepts() always thinks things are fine, yet nothing is > ever saved to the database (& I also get no errors reported - like the > T2 experiment). > > Help very much appreciated for both getting errors displayed (when > there are some) & for getting the database actually updated. > (Perhaps this is the missing T2 hidden fields?) > > Here is my processing logic: > > # Get a pointer to the Layer record (for getting default values out & > saving updated values back) > layer=db(db.gis_layer.id==t2.id).select()[0] > > if form.accepts(request.vars,session,keepvalues=True): > layer.update( > name=form.vars.name, > description=form.vars.description, > type=form.vars.type, > priority=form.vars.priority, > enabled=form.vars.enabled > ) > type_new=db(db.gis_layer_type.id==form.vars.type).select()[0].name > if type_new=="openstreetmap": > db(db['gis_layer_%s' % type_new].layer==t2.id).update( > type=form.vars.subtype > ) > elif type_new=="google": > db(db['gis_layer_%s' % type_new].layer==t2.id).update( > type=form.vars.subtype > ) > db(db.gis_key.service==type_new).update( > key=form.vars.key > ) > response.confirmation=T("Layer updated") > elif form.errors: > response.error=T("Form is invalid") > else: > response.notification=T("Please fill the form") --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---