Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Recaptcha Bundle Laravel Package

acrobat/recaptcha-bundle

Symfony2 form integration for Google reCAPTCHA. Install via Composer, register the bundle, and configure your public/private keys in config.yml. Supports disabling per environment and optional Ajax loading, helping protect forms from spam and bots.

View on GitHub
Deep Wiki
Context7

AcrobatRecaptchaBundle

SensioLabsInsight Build Status Latest Stable Version Latest Unstable Version License

This bundle provides reCAPTCHA integration with symfony2 forms.

Installation

Step 1: Use composer and enable Bundle

To install AcrobatRecaptchaBundle with composer just run the following command:

Symfony 2.3 installation

$ php composer.phar require acrobat/recaptcha-bundle:~1.0

Symfony >= 2.4 installation

$ php composer.phar require acrobat/recaptcha-bundle:~2.0

Note: In RecaptchaBundle 2.0 we dropped support for symfony 2.3, see issue #4. Both versions 1.0 and 2.0 will be maintained.

This will add the config line to the composer.json and installs the latest stable version of this bundle.

All that is left to do is to update your AppKernel.php file, and register the new bundle:

<?php

// in AppKernel::registerBundles()
$bundles = array(
    // ...
    new Acrobat\Bundle\RecaptchaBundle\AcrobatRecaptchaBundle(),
    // ...
);

Step2: Configure the bundle's

Your reCAPTCHA's public and private keys that can be found at your recaptcha admin page. Add the following to your config.yml:

# app/config/config.yml

acrobat_recaptcha:
    public_key: here_is_your_public_key
    private_key: here_is_your_private_key
    locale: %kernel.default_locale%

Note: Only public_key and private_key are required other settings will use the default values when they are not defined.

You can disable reCAPTCHA (for example in a local or test environment):

# app/config/config.yml

acrobat_recaptcha:
    // ...
    enabled: false

Load reCAPTCHA using Ajax:

# app/config/config.yml

acrobat_recaptcha:
    // ...
    ajax: true

Use https for recaptcha connections

# app/config/config.yml

acrobat_recaptcha:
    // ...
    https: auto

Possible values:

  • on : always use https
  • off : always use http
  • auto : let the browser decide what protocol to use, based on the original request protocol (default)

Basic Usage

Usage in forms

Add the following line to create the reCAPTCHA field:

<?php

public function buildForm(FormBuilder $builder, array $options)
{
    // ...
    $builder->add('recaptcha', 'recaptcha');
}

You can pass extra options to reCAPTCHA with the options attribute:

<?php

public function buildForm(FormBuilder $builder, array $options)
{
    // ...
    $builder->add('recaptcha', 'recaptcha', array(
        'attr' => array(
            'options' => array(
                'theme' => 'clean'
            )
        )
    ));
    // ...
}

List of valid options:

  • theme
  • lang
  • custom_translations
  • custom_theme_widget
  • tabindex

Visit Customizing the Look and Feel of reCAPTCHA for the details of customization.

Validation

RecaptchaType has a built-in validator, you don't need to setup anything!

You can disable the default validation by removing the existing validator in the form config:

<?php

public function buildForm(FormBuilder $builder, array $options)
{
    // ...
    $builder->add('recaptcha', 'recaptcha', array(
        // only for disabling validation
        'constraints'   => array()
    ));
}
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope