I've been trying to write my own validators using the
formencode.FancyValidator class. What I am trying to accomplish is to
validate some input as well as modify the input by stripping html
tags.  I'm not sure if formencode was designed to accomplish both of
these tasks.

Here is a simple example:


import formencode, HTMLParser
from formencode import validators
from HTMLParser import HTMLParser

class StripTags(formencode.FancyValidator):
        def _to_python(self, value, state):
                result = []
                parser = HTMLParser()
                parser.handle_data = result.append
                parser.feed(value)
                parser.close()
                return ''.join(result)

class CommentForm(formencode.Schema):
        name    = formencode.All(StripTags(), validators.NotEmpty())
        comment = formencode.All(StripTags(), validators.NotEmpty())


So in this example I am trying to validate that the name & comment
fields are not empty, as well as strip any html or script tags.  Now I
can raise an exception if any tags are encountered and that works
fine, but I'd rather  strip them out.

Am I going about this the wrong way? I'm starting to think that
formencode is only designed for validating input, and not filtering
it.

--~--~---------~--~----~------------~-------~--~----~
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