I am trying to allow a user to enter credit card information i.e card
type,card number and expiration.
Are there any standard fields available to handle these common types?
I was doing:
${.field("cardnumber",
h.text(name="cardnumber"),
required=True,
)}
I can use the below, but its kinda lame as my son would say.
Much appreciated any assistance on this.
Thanks,
Garyc
There are three validators for credit card types in formencode.validators:
- CreditCardValidator: checks that the card number is within the range
for the specified CC company, and that it passes the checksum.
- CreditCardExpires: checks that the expiration month & year is in the future.
- CreditCardSecurityCode: checks that the card verification code has
the correct number of digits for the specified CC company.
You can add additional features to the form with Javasacript, but
Pylons does not recommend a particular Javascript library because they
change frequently and sometimes one is better and sometimes another.
--
Mike Orr <slugg...@gmail.com>
On Dec 31 2009, 12:16 pm, Mike Orr <sluggos...@gmail.com> wrote:
> Mike Orr <sluggos...@gmail.com>- Hide quoted text -
>
> - Show quoted text -
I'm having a wee' issue on this problem of introducing the credit card
checks.
Below is my verification class:
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()
Essentially this results in three missing fields being show i.e
ccType,ccNumber and cc.
Could somebody be so kind and enlighten me on the correct syntax for
this method?
Much appreciated,
Garyc
> > - Show quoted text -- Hide quoted text -
Oh, they need to be post_validators because they operate on multiple
fields. So make string fields for all of them, then put the credit
card validators in post_validators.
--
Mike Orr <slugg...@gmail.com>
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.
Thanks,
Garyc
On Jan 1, 12:29 pm, Mike Orr <sluggos...@gmail.com> wrote:
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 <slugg...@gmail.com>
Garyc
On Jan 1, 3:42 pm, Mike Orr <sluggos...@gmail.com> wrote:
> On Fri, Jan 1, 2010 at 11:16 AM, gazza <burslem2...@yahoo.com> 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