Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

afoysal's avatar

Google reCaptcha Validation

I am am working with Google reCaptcha in a Registration page using Laravel 8. My View (blade) page code is like below.

<div class="form-group mt-5">
    <div class="g-recaptcha" data-sitekey="sitekeytext"></div>
</div>
@error('g-recaptcha-response')
  <div class="alert alert-danger mt-1 mb-1">{{ $message }}</div>
@enderror

My Controller code is like below,

$request->validate([
  'g-recaptcha-response' => 'required',
],
[
   'g-recaptcha-response.required' => 'Captcha is Required',       
]);

After submitting Form I am getting Captcha is Required validation message.

enter image description here

Same code is working perfectly on Login page.

0 likes
5 replies
afoysal's avatar

Thanks @a4ashraf . I am not using any plugin. I checked my JS file. There is no error. Same code is working in Login page but not working in Registration page. Thanks.

a4ashraf's avatar

@afoysal

if you are not using any plugin. then check your JS implementation maybe you miss the something

if you share your implementation code that could be helped

1 like
afoysal's avatar

Thanks @a4ashraf . How same code is working in Login page. ?

I added below code in header.

<script src='https://www.google.com/recaptcha/api.js' async defer></script>

I added below code in register.blade.php file.

<div class="form-group mt-5">
                            <div class="g-recaptcha" data-sitekey="sitekeytext">    </div>
</div>
   @error('g-recaptcha-response')
            <div class="alert alert-danger mt-1 mb-1">{{ $message }}</div>
   @enderror

I added below code in RegisteredUserController.php

$request->validate([
      'g-recaptcha-response' => 'required',
  ],
 [
      'g-recaptcha-response.required' => 'Captcha is Required',         
]);

Same code is working in Login page but it is not working in Registration page.

Please or to participate in this conversation.