Any plan to support Invisible ReCaptcha?
Is Invisible ReCaptcha support planned? Would PR with support for it be welcomed?
Looks like the only change is placing the attributes on a button instead of a div. If you'd like to add an InvisibleRecaptchaWidget and InvisibleRecaptchaSubmit field, that would be fine. I'd prefer to wait until it's out of beta though.
@davidism It seems out of beta now.
https://developers.google.com/recaptcha/intro
@ar-anvd @RabsRincon I'd be happy to review a PR if you're still interested.
We started using the Invisible ReCaptcha a while back without having to do any major modifications to our codebase.
flask configuration
RECAPTCHA_DATA_ATTRS = {'bind': 'recaptcha-submit', 'callback': 'onSubmitCallback', 'size': 'invisible'}
controllers.py
from flask_wtf.recaptcha.fields import RecaptchaField
from wtforms.fields.core import StringField
class TestForm(FlaskForm):
the_input = StringField('Write stuff here...')
recaptcha = RecaptchaField()
@bp.route('/test', methods=['GET', 'POST'])
def test():
form = TestForm()
if form.validate_on_submit():
print('everything a-ok')
else:
print(form.errors)
return render_template('test.html', form=form)
test.html
<html>
<head></head>
<body>
<script>
function onSubmitCallback(token) {
document.getElementById("test-form").submit();
}
</script>
<form id="test-form" action="" method="post">
{{ form.the_input }}
{{ form.recaptcha }}
<button id="recaptcha-submit">
Test me
</button>
</form>
</body>
</html>
I don't think the method that @mazzer shared still works. Is there a better way to set this up?
It still worked for me last week, haven't tried today. Any particular reason why you say it now doesn't work?
@fili I used the above code for invisible captcha and I get "urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)>" on "form.validate_on_submit"
Edit: Fixed it by installing Certificates.command
@nullbaka Are you using reCaptcha v2: Invisible reCAPTCHA badge? This one works with @mazzer example. I am not sure where that certificate error comes from, may be related to something else or maybe v3.
@fili yes am using invisible reCAPTCHA on Mac OSX Catalina. I googled the error and found that this issue can be fixed by installing certificates.command. Didn't find any relation to Recaptcha or form validation. All's working good now. Let's see if I face any issues on deployment.