Adding a captcha to a form as shown in the book requires too much work!! ;-) Here is a simpler way to do it.
The idea is using a fake widget.
Model:
def captcha_field(request=request):
from gluon.tools import Recaptcha
w = lambda x,y: Recaptcha(request,
'xxxxxxxxxxxxxxxxxxxxxxx',
'yyyyyyyyyyyyyyyyyyyyyyy')
return Field('captcha', 'string', label='verify', widget=w, default='ok')
Controller:
form = SQLFORM.factory(Field('name', requires=IS_NOT_EMPTY()), Field('email', requires=[IS_NOT_EMPTY(), IS_EMAIL()]), Field('content', 'text', requires=IS_NOT_EMPTY()), captcha_field()), ) if form.process().accepted: ... ... ...
Comments (2)
0
rochacbruno 11 years ago
Nice slice!
I would change a little to:
And using with
Also I think it can be included as
replies (1)
0
jeremy-martin-11354 9 years ago
Holy cow, so helpful. The only thing I can add is that if you're doing a register form with a password, doing the SQLFORM factory will not give you the "verify password" field by default. And if you update, you'll need to filter the form vars. So this is what I'm doing: