import formencode
from pylons.decorators import validate

class EmailForm(formencode.Schema):
    allow_extra_fields = True
    filter_extra_fields = True
    email = formencode.validators.Email(not_empty=True,
messages={'empty':'Please enter a email now!!'})

class TestvalidateController(BaseController):

    def form(self):
        return render('/simpleform.htm')

    @validate(schema=EmailForm(), form='form', post_only=False, on_get=True)
    def submit(self):
        return 'Your email is: %s .' % self.form_result['email']


Email validator defines following messages, and you can override them as the
sample.
    messages = {
        'empty': _('Please enter an email address'),
        'noAt': _('An email address must contain a single @'),
        'badUsername': _('The username portion of the email address is
invalid (the portion before the @: %(username)s)'),
        'socketError': _('An error occured when trying to connect to the
server: %(error)s'),
        'badDomain': _('The domain portion of the email address is invalid
(the portion after the @: %(domain)s)'),
        'domainDoesNotExist': _('The domain of the email address does not
exist (the portion after the @: %(domain)s)'),
        }

On Sat, May 8, 2010 at 11:17 PM, Haron Media <[email protected]> wrote:

>
> I'm looking through the FormEncode docs and source, trying to figure out
> how to specify a single message in case validation fails for a field.
> For example, email. I want to produce single message, ie. "Invalid email
> address", instead of several depending on the kind of validation failure
> (badType, badUsername, empty, ...).
>
> Other than writing my own validator, or parsing Invalid exception's
> error dict for fields that failed, is there another way?
>
>
> Thanks,
>
>
> Vlad
>
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<pylons-discuss%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/pylons-discuss?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" 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/pylons-discuss?hl=en.

Reply via email to