On Fri, Jan 1, 2010 at 11:16 AM, gazza <[email protected]> wrote: > HiMike, > > Firstly thankyou for helping me. > > Its thowing me trying to understand "post_validators". What is > post_validators? > > Within my code I have: > > > @restrict('POST') > @validate(schema=ClientNewForm(),form='registration') > > So when the form is posted the verification takes place by calling > ClientNewForm() > > class ClientNewForm(formencode.Schema): > allow_extra_fields = True > filter_extra_fields = True > firstname = formencode.validators.String(not_empty=True) > lastname = formencode.validators.String(not_empty=True) > cardType = formencode.validators.String(not_empty=True) > cardNumber = formencode.validators.String(not_empty=True) > > ccType=cardType > ccNumber=cardNumber > cc = formencode.validators.CreditCardValidator() > > > If this isnt too much to ask, could you provide a simple example or > point me to a resource that > explains this to me.
Sorry, they're called chained_validators. http://formencode.org/Validator.html import formencode.validators as v class ClientNewForm(formencode.Schema): allow_extra_fields = True filter_extra_fields = True firstname =v.String(not_empty=True) lastname = v.String(not_empty=True) cc_type =v.String(not_empty=True) cc_number = v.String(not_empty=True) cc_expires_month = v.String(not_empty=True) cc_expires_year = v.String(not_empty=True) cc_code = v.String(not_empty=True) chained_validators = [ v.CreditCardValidator("cc_type", "cc_number"), v.CreditCardExpires("cc_expires_month", "cc_expires_year), v.CreditCardSecurityCode("cc_type", "cc_code"), ] Regular validators operate on a scalar value, but chained validators operate on the entire form dict. The entire schema itself also operates on the form dict, as do pre validators, which are all explained in the URL above. To figure the arguments out, I looked at the source of formencode/validators.py. The CreditCard* validators each have an '__unpackargs__' attribute, which lists the positional arguments the constructor requires. In this case, it needs to know the names of the relevant fields in your form. This should be better documented, and when I have time I'm planning to write a better FormEncode manual. In the meantime, look through the source of formencode, particularly validators.py, api.py, schema.py, and declarative.py, and that may give you a better idea how they all work. -- Mike Orr <[email protected]> -- 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.
