Some of the information here may be outdated, please check the book instead
[edit]

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.

© 2008-2010 by Massimo Di Pierro - All rights reserved - Powered by web2py - design derived from a theme by the earlybird
The content of this book is released under the Artistic License 2.0 - Modified content cannot be reproduced.