2017 © Pedro Peláez
 

symfony-bundle recaptcha-bundle

reCAPTCHA support for Symfony2 with easy-to-use integration to Security Component.

image

dmishh/recaptcha-bundle

reCAPTCHA support for Symfony2 with easy-to-use integration to Security Component.

  • Saturday, December 20, 2014
  • by dmishh
  • Repository
  • 3 Watchers
  • 4 Stars
  • 1,257 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 5 Forks
  • 2 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

reCAPTCHA support for Symfony2

Features

  • Easy-to-use
  • Service-oriented architecture
  • Integration into forms
  • Integration into Security Component — for protecting login form with reCAPTCHA
  • Independent reCAPTCHA API realization (Recaptcher by default)
  • Both, PHP and Twig template engines support

Installation using Composer

  1. Add the following to your composer.json file:, (*1)

    // composer.json
    {
        // ...
        "require": {
            // ...
            "dmishh/recaptcha-bundle": "1.0.*"
        }
    }
    
  2. Update dependencies, run from command line:, (*2)

    php composer.phar update
    
  3. Register the bundle in your AppKernel.php file:, (*3)

    <?php
    
    // in AppKernel::registerBundles()
    $bundles = array(
        // ...
        new Dmishh\Bundle\RecaptchaBundle\RecaptchaBundle()
    );
    

Configuration

Your reCAPTCHA's public and private keys that can be found at your recaptcha admin page. Configure RecaptchaBundle in your config.yml:, (*4)

``` yaml, (*5)

...

recaptcha: public_key: 6LeJg90SAAAAAA9yk0zeNrF8QKaxqR_bV_9SNLz9 private_key: 6LeJg90SAAAAAEuTLEbZuymhkigzzPm2_wsSdA8j use_https: false # optional, (*6)


## Usage in forms Add the following line to create the reCAPTCHA field: ``` php <?php // your form ... public function buildForm(FormBuilder $builder, array $options) { // ... $builder->add('recaptcha', 'recaptcha'); }

You can pass extra options to reCAPTCHA with the widget_options option:, (*7)

``` php <?php, (*8)

// your form ..., (*9)

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


List of valid options: * theme * lang * custom_translations * custom_theme_widget * tabindex Visit [Customizing the Look and Feel of reCAPTCHA](https://developers.google.com/recaptcha/docs/customization) for the details of customization. ### Validation `RecaptchaType` has built-in validator, you don't need to do anything more. Just use it! But if you need to **disable** validation for some reasons, then remove existing validator: ``` php <?php // your form ... public function buildForm(FormBuilder $builder, array $options) { // ... $builder->add('recaptcha', 'recaptcha', array( // only for disabling validation 'constraints' => array() )); }

Usage in login form

You need to define RecaptchaFormAuthenticationListener as default listener for form authentication in services.yml:, (*11)

``` yaml, (*12)

...

security.authentication.listener.form: class: Dmishh\Bundle\RecaptchaBundle\Security\Firewall\RecaptchaFormAuthenticationListener parent: security.authentication.listener.abstract calls: - [setRecaptcha, [@recaptcha]] abstract: true, (*13)


Second parameter in *setRecaptcha* method is used for disabling validator. This might be useful when you need to disable check in dev environment. For example: ``` yaml security.authentication.listener.form: class: Dmishh\Bundle\RecaptchaBundle\Security\Firewall\RecaptchaFormAuthenticationListener parent: security.authentication.listener.abstract calls: - [setRecaptcha, [@recaptcha, %kernel.debug%]] abstract: true

Now you need to add recaptcha field to your form. If you are using your own form type, than add recaptcha field to your form as described [above](#Usage in forms)., (*14)

Otherwise, add those lines to your Controller which renders login form and to corresponding Twig template:, (*15)

``` php <?php, (*16)

// your controller ..., (*17)

public function yourAction(Request $request) { // ... $recaptcha = $this->createForm($this->get('form.type.recaptcha'));, (*18)

return array(
    // ...
    'recaptcha' => $recaptcha->createView()
);

}, (*19)


``` jinja <!-- template --> <label for="recaptcha_response_field">Captcha:</label> {{ form_widget(recaptcha) }}

This documentation is based on EWZRecaptchaBundle's docs., (*20)

Roadmap

1.0.* (TODO)

  • Add docs about manual installation and usage reCAPTCHA with ajax

1.0

  • Initial version

The Versions

20/12 2014

dev-master

9999999-dev https://github.com/dmishh/RecaptchaBundle

reCAPTCHA support for Symfony2 with easy-to-use integration to Security Component.

  Sources   Download

MIT

The Requires

 

symfony2 bundle recaptcha

20/12 2014

1.0.1

1.0.1.0 https://github.com/dmishh/RecaptchaBundle

reCAPTCHA support for Symfony2 with easy-to-use integration to Security Component.

  Sources   Download

MIT

The Requires

 

symfony2 bundle recaptcha

04/12 2013

1.0.0

1.0.0.0 https://github.com/dmishh/RecaptchaBundle

reCAPTCHA support for Symfony2 with easy-to-use integration to Security Component.

  Sources   Download

MIT

The Requires

 

symfony2 bundle recaptcha

27/05 2013

1.0.0-rc1

1.0.0.0-RC1 https://github.com/dmishh/RecaptchaBundle

reCAPTCHA support for Symfony2 with easy-to-use integration to Security Component.

  Sources   Download

MIT

The Requires

 

symfony2 bundle recaptcha

07/05 2013

1.0.0-beta2

1.0.0.0-beta2 https://github.com/dmishh/RecaptchaBundle

reCAPTCHA support for Symfony2 with easy-to-use integration to Security Component.

  Sources   Download

MIT

The Requires

 

symfony2 bundle recaptcha

06/05 2013

1.0.0-beta1

1.0.0.0-beta1 https://github.com/dmishh/RecaptchaBundle

reCAPTCHA support for Symfony2 with easy-to-use integration to Security Component.

  Sources   Download

MIT

The Requires

 

symfony2 bundle recaptcha

03/03 2013

1.0.0-alpha1

1.0.0.0-alpha1 https://github.com/dmishh/RecaptchaBundle

reCAPTCHA support for Symfony2 with easy-to-use integration to Security Component.

  Sources   Download

MIT

The Requires

 

symfony2 bundle recaptcha