Skip to content
● Critical PHP security fixes are out: update PHP on your Grav sites. What to do →

ReCaptcha-validation client-side not working

form

Solved by Mirko View solution

Started by Mirko 7 years ago · 1 replies · 2415 views
7 years ago

Hey, I have the same problem as the guy in this post: /forum/archive/recaptcha-not-validated-client-side-or-how-to-deal-with-form-errors-t9025

I am using Google ReCaptcha in my modular form template.
The validation of the ReCaptcha is perfectly working on server-side, but I can't get it run on client-side. So the user won't get any failure message before submitting the form.

It would be much nicer, if the user would get a message before sending the form, in which he is asked to fill out the recaptcha.

Thank you!

7 years ago Solution

I found a solution. Not the cleanest but it works (the ID of my form is "contact-form"):

JS
    var form = document.getElementById('contact-form');
    form.addEventListener("submit", function(event){
            if (grecaptcha.getResponse() === '') {
                event.preventDefault();
                alert('Bitte füllen Sie das ReCaptcha aus.');
            }
        }
        , false);

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by TomW, 3 days ago
3 79 2 days ago
Forms & Blueprints · by Japhy, 3 weeks ago
2 394 2 weeks ago
Forms & Blueprints · by FrViPofm, 1 month ago
5 395 1 month ago
Forms & Blueprints · by Ton Haarmans, 6 years ago
13 2388 8 months ago
Forms & Blueprints · by Hugo Oliveira, 9 months ago
0 844 9 months ago