captcha and recaptha

[edit|delete]

If you need to use captcha we strongly suggest outsourcing to recaptcha.net

It could not be easier. here is how to:

  • register at recaptcha.net (they give you a privatekey and a publickey)
  • download this file and save it as models/recaptcha.py
  • use the RECAPTCHA helper (defined in file above) as in the following...

Example:

public_key='xxx'  ### provided by recaptcha.net
private_key='xxx' ### provided by recaptcha.net
def index():
    form=FORM(RECAPTCHA(request,public_key,private_key),INPUT(_type='submit'))
    if form.accepts(request.vars,session): response.flash='done!'
    elif form.errors.has_key('captcha'): response.flash='invalid capctha'
    else: response.flash='some other error in your form'
    return dict(form=form)

The RECAPTCHA helper works very much as the input helper but it always take (request,publickey,privatekey) and validates itself. If it does no pass validation an error message is stored in form.errors['captcha'] but not displayed. It is up to the developer to display the error as appropriate.



Post a comment