Reputation: 679
i was working with custom forms in web2py and faced 2 problems
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 ?
Upvotes: 0
Views: 1976
Reputation: 25536
crud.create()
handles the form processing automatically, so you should not call form.accepts()
after it. Please read the book section on Crud.
Upvotes: 1
Reputation: 8168
If you have web2py 2.0+ try to replace your controller code with this:
def new():
form=SQLFORM(db.i2l_letter)
print form.errors
if form.process().accepted:
response.flash='Bitte warten'
elif form.errors:
response.flash='Bitte fuellen sie das Formular richtig aus'
return dict(form=form)
Upvotes: 1