Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RecaptchaV3. Error «incorrect-captcha-sol» #110

Open
suddhah opened this issue Nov 22, 2022 · 0 comments
Open

RecaptchaV3. Error «incorrect-captcha-sol» #110

suddhah opened this issue Nov 22, 2022 · 0 comments

Comments

@suddhah
Copy link

suddhah commented Nov 22, 2022

  • noCaptcha Version: 13.0.0
  • Laravel Version: 9.16.0
  • PHP Version: 8.1.5

Description:

When verifying the request, the error "incorrect-captcha-sol" is returned. I tried recreating recaptcha keys, different connection methods, clearing browser cookies, opening the site through a different browser.

Steps To Reproduce:

For example FeedbackController.php file:

public function post(Request $request)
{
    $captcha = new NoCaptchaV3(
        'RECAPTCHAV3_SECRET',
        'RECAPTCHAV3_SITEKEY'
    );

    if ($request->all() && $request['g-recaptcha-response']) {
        $response = $captcha->verify($request['g-recaptcha-response'] ?? null);

        if ($response->isSuccess()) {
            ...
        } else {
            dd($response);
        }
    }
}

feedback.blade.php:

<form action="{{ route('feedback.post') }}" method="POST" name="formFeedback" class="contact-form contact__form">
    {{ csrf_field() }}
    <input type="hidden" value="{{$page}}" name="page" />
    <input class="contact-form__input" name="phone" type="text" placeholder="Телефон*">
    <input class="contact-form__input" name="name" type="text" placeholder="Имя">
    <textarea class="contact-form__input contact-form__area" name="msg" placeholder="Текст сообщения"></textarea>
    <span class="contact-form__policy">Нажимая "Отправить" вы соглашаетесь с политикой обработки персональных данных</span>
    <input class="contact-form__btn btn" type="submit" value="Отправить">

    {{ no_captcha()->input('g-recaptcha-response') }}
</form>

{{ no_captcha()->script() }}
{{ no_captcha()->getApiScript() }}

<script>
    grecaptcha.ready(() => {
        window.noCaptcha.render('formFeedback', (token) => {
            let recaptchaInputs = document.querySelectorAll('#g-recaptcha-response');
            recaptchaInputs.forEach(function (element) {
                element.value = token;
            });
        });
    });
</script>

main.js:

const recaptchaSitekey = 'RECAPTCHAV3_SITEKEY';

$('.contact-form').on('submit', function(e) {
    e.preventDefault();
    var formData = $(this).serializeArray().reduce(function(obj, item) {
        obj[item.name] = item.value;
        return obj;
    }, {});

    let url = $(this).attr('action');
    return axios
        .post(url, formData)
        .then(function(res) {
            if(res.data.status=='ok'){
                notifier.success('Спасибо, ваше сообщение успешно отправлено!');

                grecaptcha.reset(recaptchaSitekey);
                grecaptcha.ready(() => {
                    window.noCaptcha.render('thatForm', (token) => {
                        var recaptchaInputs = document.querySelectorAll('#g-recaptcha-response');
                        recaptchaInputs.forEach(function (element) {
                            element.value = token;
                        });
                    });
                });
            }
            else{
                notifier.alert('Что-то пошло не так :( Попробуйте позже...')
            }
        })
        .catch(error => {
            notifier.alert('Что-то пошло не так :( Попробуйте позже...')

            console.error(error);
        });
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant