Skip to content

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

@suddhah

Description

@suddhah
  • 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);
        });
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions