i was working with custom forms in web2py and faced 2 problems
- 1) errors are not catched and displayed
- 2) form is not submitted :
after a validation/verfication i got those values:
form.accepts(request.vars, session) => False
form.errors => <Storage ()>
now what i have :
controller:
def new():
form=crud.create(db.i2l_letter)
print form.errors
if form.accepts(request.vars, session):
response.flash='Bitte warten'
elif form.errors:
response.flash='Bitte fuellen sie das Formular richtig aus'
else:
pass
return dict(form=form)
view:
{{if form.errors:}}
Your submitted form contains the following errors:
<ul>
{{=form.errors.date_format}}
{{for fieldname in form.errors:}}
<li>{{=fieldname}} error: {{=form.errors[fieldname]}}</li>
{{pass}}
</ul>
{{form.errors.clear()}}
{{pass}}
{{=form.custom.begin}}
<table>
<tr>
<td>{{=form.custom.label.date_format}}</td>
<td>{{=form.custom.label.myref}}</td>
<td>{{=form.custom.label.yourref}}</td>
</tr>
<tr>
<td>{{=form.custom.widget.date_format}}</td>
<td>{{=form.custom.widget.myref}}</td>
<td>{{=form.custom.widget.yourref}}</td>
</tr>
</table>
<div>{{=form.custom.submit}}</div>
{{=form.custom.end}}
{{pass}}
so what am i doing wrong ?
If you have web2py 2.0+ try to replace your controller code with this: