flask-wtf icon indicating copy to clipboard operation
flask-wtf copied to clipboard

Any plan to support Invisible ReCaptcha?

Open AbrilRBS opened this issue 8 years ago • 9 comments

Is Invisible ReCaptcha support planned? Would PR with support for it be welcomed?

AbrilRBS avatar Feb 13 '17 09:02 AbrilRBS

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 avatar Feb 24 '17 15:02 davidism

@davidism It seems out of beta now.

https://developers.google.com/recaptcha/intro

ar-anvd avatar Jun 26 '17 02:06 ar-anvd

@ar-anvd @RabsRincon I'd be happy to review a PR if you're still interested.

davidism avatar Jun 26 '17 03:06 davidism

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>

mazzer avatar Jul 04 '17 11:07 mazzer

I don't think the method that @mazzer shared still works. Is there a better way to set this up?

rushilsrivastava avatar May 30 '20 23:05 rushilsrivastava

It still worked for me last week, haven't tried today. Any particular reason why you say it now doesn't work?

fili avatar May 31 '20 07:05 fili

@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

kirtimukh avatar Jun 04 '20 09:06 kirtimukh

@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 avatar Jun 04 '20 13:06 fili

@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.

kirtimukh avatar Jun 04 '20 14:06 kirtimukh