karser / KarserRecaptcha3Bundle

Google ReCAPTCHA v3 for Symfony
MIT License
158 stars 21 forks source link

The captcha value is missing. API method #55

Closed lassanadiakite closed 1 year ago

lassanadiakite commented 2 years ago

Hello, I work in API mode on symfony 5 (ApiPlatform) with nuxtjs in Front. After implementing your bundle. I get as error: The captcha value is missing. Thank you for your reply.

br-development commented 2 years ago

Have you found the solution ? If not on my side I've removed the property and constraint from entity to put it directly on the form and it solved the problem.

Enz000 commented 2 years ago

see the api method in the readme

you need to implement a javascript method

<script src="https://www.google.com/recaptcha/api.js?render=<siteKey>"></script>

<script>
const siteKey = '*****************-**-******-******';

//either on page load
grecaptcha.ready(function() {
    grecaptcha.execute(siteKey, {
        action: 'homepage'
    }).then(function(token) {
        //the token will be sent on form submit
        $('[name="captcha"]').val(token);
        //keep in mind that token expires in 120 seconds so it's better to add setTimeout.
    });
});

//or on form post:
grecaptcha.ready(function() {
    grecaptcha.execute(siteKey, {
        action: 'homepage'
    }).then(function(token) {
        //submit the form
        return http.post(url, {email, captcha: token});
    });
});
</script>