reCAPTCHA link in online web2py book

72 views
Skip to first unread message

lucas

unread,
Jan 22, 2024, 9:01:02 AMJan 22
to web2py-users
hello one and all,

the link for reCAPTCHA, or, "http://web2py.com/books/default/reference/29/recaptcha", under the online web2py book, "http://web2py.com/books/default/chapter/29/09/access-control#CAPTCHA-and-reCAPTCHA", seems to by unreferenced.

is this feature still working in the latest version of web2py, 2.27.1?  is it still free?  is it still good to use?

thank you, lucas

lucas

unread,
Jan 28, 2024, 8:41:01 AMJan 28
to web2py-users
anyone on this, at all?

Dave S

unread,
Jan 31, 2024, 3:46:28 AMJan 31
to web2py-users
On Sunday, January 28, 2024 at 5:41:01 AM UTC-8 lucas wrote:
anyone on this, at all?


Sorry, I haven't used recaptcha, but I think there was a recent thread about it in the py4web forum.

Good luck

/dps

chriii...@gmail.com

unread,
Jan 31, 2024, 9:02:08 AMJan 31
to web2py-users
Hello.

Recpatcha is still working like a charm. 

Here are some examples about how to use it.

if you want to have Recaptcha in login form, set it like this:

in models.py
#import recaptcha
from gluon.tools import Recaptcha2

#enable recaptcha in login form.
auth.settings.captcha = Recaptcha2(request, public_key='key1', private_key='key2', label='')


If you want to use it in SQLFORM.
define some functions for convenience in models.py or in other place

ex: 
#function to be used in a form without database
def captcha_field(request=request):
    w = lambda x, y: Recaptcha2(request,
                                'public_key',
                               'private_key',
                               )

    return Field('captcha', 'string', label='', widget=w, default='ok')


#function to be used in a sqlform
def captcha_sqlform():
    recaptcha2 = Recaptcha2(request, 'public_key', 'private_key', '')

    return DIV(LABEL("", _class="form-control-label col-sm-3"),DIV(recaptcha2, _class="col-sm-9"), _class="form-group row",_name="recaptcha_form")


#append the recaptcha to sqlform
form = SQLFORM(db.table, keep_values=True)
form[0].insert(-1, captcha_sqlform())

This will add the recpatcha validation to the form.

Greetings.
Chris.
Reply all
Reply to author
Forward
0 new messages