Very Confused: formencode.validators.Email

22 views
Skip to first unread message

Bruce Wade

unread,
Jul 3, 2011, 2:07:42 PM7/3/11
to pylons-...@googlegroups.com
At this point I am very confused I am trying to use formencode with Pyramid all the validators are working except Email

form.py
----------------------
import formencode
from formencode import Schema, validators

class NewClient(Schema):
    filter_extra_fields = True
    allow_extra_fields = True
   
    height_feet = validators.String(not_empty=True)
    height_inch = validators.String(not_empty=True)
    cweight = validators.Int(not_empty=True)
    tweight = validators.Int(not_empty=True)
    gender = validators.String(not_empty=True)
    fname = validators.String(not_empty=True)
    age = validators.Int(not_empty=True)
    cmail = validators.Email(not_empty=True),  # Have no idea why this is not working or being called when left blank
    pgoal = validators.String(not_empty=True)
    phone = validators.String(not_empty=True)
-------------------

views.py
------------------
def new_client(request):
    from forms import NewClient
    from pyramid_simpleform import Form
    from pyramid_simpleform.renderers import FormRenderer
   
    form = Form(request, schema=NewClient)
    if form.validate():
        details['valid'] = True
   
    return dict(newclient=details, form=FormRenderer(form))
------------------

Now when I submit the form all validation is working except for the cmail, I can leave it blank, add something that isn't a email address and it never returns invalid. Is there a bug in the code or am I missing something simple?

--
--
Regards,
Bruce Wade
http://ca.linkedin.com/in/brucelwade
http://www.wadecybertech.com
http://www.warplydesigned.com
http://www.fitnessfriendsfinder.com

Detectedstealth

unread,
Jul 5, 2011, 12:09:40 AM7/5/11
to pylons-discuss
Nevermind I found my typo the , at the end of that validation:
cmail = validators.Email(not_empty=True),

Apparently that causes the validation to be ignored :D

Georges Dubus

unread,
Jul 5, 2011, 3:55:44 AM7/5/11
to pylons-...@googlegroups.com
After the line
cmail = validators.Email(not_empty=True),

The value of cmail is (validators.Email(not_empty=True),) : it's a tuple. That's why it's ignored during the validation.
Reply all
Reply to author
Forward
0 new messages