backend2-plus/google-captcha-bundle

Google reCAPTCHA bundle for Symfony

v1.1.0 2025-08-05 20:08 UTC

This package is auto-updated.

Last update: 2025-09-05 20:40:44 UTC


README

Simple Symfony bundle for Google reCAPTCHA integration.

Installation

composer require sasa1007/google-captcha-bundle

Note: After installation, you need to manually configure the bundle as described below.

Configuration

Create configuration file config/packages/google_captcha.yaml:

google_captcha:
    secret: '%env(GOOGLE_CAPTCHA_SECRET)%'

Add to your .env file:

GOOGLE_CAPTCHA_SECRET=your_google_recaptcha_secret_key

Note: Replace your_google_recaptcha_secret_key with your actual Google reCAPTCHA secret key from Google reCAPTCHA Admin Console.

Usage

use BeckUp\GoogleCaptchaBundle\Service\GoogleCaptchaService;

class YourController extends AbstractController
{
    public function someAction(Request $request, GoogleCaptchaService $captchaService)
    {
        $result = $captchaService->verify($request);
        
        if ($result->success) {
            // reCAPTCHA passed
        } else {
            // reCAPTCHA failed
        }
    }
}

Frontend

Add Google reCAPTCHA script to your template:

<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<div class="g-recaptcha" data-sitekey="your_site_key"></div>

Uninstallation

To remove the bundle:

  1. Delete configuration file:
rm config/packages/google_captcha.yaml
  1. Remove from composer:
composer remove sasa1007/google-captcha-bundle

Note: The bundle is automatically unregistered and service definitions are removed when you uninstall the package.