accepts only validates field variables in fields=[...] upon moving
them from request.vars into form.vars. field variables that are
computed programmatically (as in your case) cannot be validated since
web2py cannot report the error to the user via the form.
There are ways around this. For example
form=SQLFORM(db.shapecolor,fields=['shapename','colorname'])
shapecolor=str(request.vars.shapename)+str
(request.vars.colorname)
form.vars.shapecolor,form.errors.shapecolor=\
db.shapecolor.shapecolor.requires(shapecolor)
if form.errors.shapecolor:
response.flash=form.errors.shepcolor ### notify user
elif form.accepts(request.vars,session):
....
Massimo
On Jan 11, 2:55 am, annet <[email protected]> wrote:
> Massimo,
>
> So, even though form.vars.shapecolor=str(request.vars.shapename)+str
> (request.vars.colorname) comes first in the following code:
>
> def index():
> from gluon.sqlhtml import form_factory
> form=SQLFORM(db.shapecolor,fields=['shapename','colorname'])
> form.vars.shapecolor=str(request.vars.shapename)+str
> (request.vars.colorname)
> if form.accepts(request.vars,session):
> response.flash='form accepted'
> elif form.errors:
> response.flash='form has errors (a shape with this color
> already exists)'
> else:
> response.flash='please fill the form'
> return dict(form=form)
>
> ... the assignment is done after validation. I thought that
> form.accepts(request.vars,session) would take care of validating all
> three variables. I there another way to validate shapecolor?
>
> Best regards,
>
> Annet.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" 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
-~----------~----~----~----~------~----~------~--~---