2017 © Pedro Peláez
 

symfony-bundle recaptcha-bundle

This bundle provides easy reCAPTCHA form field integration, fork from excelwebzone

image

tomfun/recaptcha-bundle

This bundle provides easy reCAPTCHA form field integration, fork from excelwebzone

  • Friday, March 14, 2014
  • by tomfun1990@gmail.com
  • Repository
  • 1 Watchers
  • 1 Stars
  • 30 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 130 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

EWZRecaptchaBundle

This bundle provides easy reCAPTCHA form field for Symfony., (*1)

Installation

To install EWZRecaptchaBundle with Composer just add the following to your composer.json file:, (*2)

// composer.json
{
    // ...
    "require": {
        // ...
        "excelwebzone/recaptcha-bundle": "dev-master"
    }
}

NOTE: Please replace dev-master in the snippet above with the latest stable branch, for example 2.0.*., (*3)

Then, you can install the new dependencies by running Composer's update command from the directory where your composer.json file is located:, (*4)

$ php composer.phar update

Now, Composer will automatically download all required files, and install them for you. All that is left to do is to update your AppKernel.php file, and register the new bundle:, (*5)

registerNamespaces(array(
    // ...
    'EWZ'              => __DIR__.'/../vendor/bundles',
    // ...
));
```

Now use the ``vendors`` script to clone the newly added repositories
into your project:

```bash
$ php bin/vendors install
```

### Step 1 (alternative): Using submodules (Symfony 2.0.x)

If you're managing your vendor libraries with submodules, first create the
`vendor/bundles/EWZ/Bundle` directory:

``` bash
$ mkdir -pv vendor/bundles/EWZ/Bundle
```

Next, add the necessary submodule:

``` bash
$ git submodule add git://github.com/excelwebzone/EWZRecaptchaBundle.git vendor/bundles/EWZ/Bundle/RecaptchaBundle
```

### Step2: Configure the autoloader

Add the following entry to your autoloader:

``` php
registerNamespaces(array(
    // ...

    'EWZ' => __DIR__.'/../vendor/bundles',
));
```

### Step3: Enable the bundle

Finally, enable the bundle in the kernel:

``` php
add('recaptcha', 'ewz_recaptcha');
    // ...
}
```

You can pass extra options to reCAPTCHA with the "attr > options" option:

``` php
add('recaptcha', 'ewz_recaptcha', array(
        'attr' => array(
            'options' => array(
                'theme' => 'clean'
            )
        )
    ));
    // ...
}
```

To validate the field use:

``` php
false``` then the annotation will not work. You have to also set ```constraints```:

``` php
add('recaptcha', 'ewz_recaptcha', array(
        'attr'          => array(
            'options' => array(
                'theme' => 'clean'
            )
        ),
        'mapped' => false,
        'constraints'   => array(
            new True()
        )
    ));
    // ...
```


Cool, now you are ready to implement the form widget:

**PHP**:

``` php
setTheme($form, array('EWZRecaptchaBundle:Form')) ?>

widget($form['recaptcha'], array(
    'attr' => array(
        'options' => array(
            'theme' => 'clean',
        ),
    ),
)) ?>

Twig:, (*6)

``` jinja {% form_theme form 'EWZRecaptchaBundle:Form:ewz_recaptcha_widget.html.twig' %}, (*7)

{{ form_widget(form.recaptcha, { 'attr': { 'options' : { 'theme' : 'clean', }, } }) }}, (*8)


If you are not using a form, you can still implement the reCAPTCHA field using JavaScript: **PHP**: ``` php <div id="recaptcha-container"></div> <script type="text/javascript"> $(document).ready(function() { $.getScript("<?php echo \EWZ\Bundle\RecaptchaBundle\Form\Type\RecaptchaType::RECAPTCHA_API_JS_SERVER ?>", function() { Recaptcha.create("<?php echo $form['recaptcha']->get('public_key') ?>", "recaptcha-container", { theme: "clean", }); }); }; </script>

Twig:, (*9)

``` jinja , (*10)


## Customization If you want to use a custom theme, put your chunk of code before setting the theme: ``` jinja
Incorrect please try again
Enter the words above: Enter the numbers you hear:
{% form_theme form 'EWZRecaptchaBundle:Form:ewz_recaptcha_widget.html.twig' %} {{ form_widget(form.recaptcha, { 'attr': { 'options' : { 'theme' : 'custom', }, } }) }}

Further reading: Customizing the Look and Feel of reCAPTCHA, (*11)

The Versions

14/03 2014

dev-master

9999999-dev https://github.com/tomfun/EWZRecaptchaBundle

This bundle provides easy reCAPTCHA form field integration, fork from excelwebzone

  Sources   Download

MIT

The Requires

 

recaptcha

02/09 2013

v1.0.0

1.0.0.0 https://github.com/excelwebzone/EWZRecaptchaBundle

This bundle provides easy reCAPTCHA form field integration

  Sources   Download

MIT

The Requires

 

recaptcha

10/11 2012

2.0.x-dev

2.0.9999999.9999999-dev https://github.com/excelwebzone/EWZRecaptchaBundle

This bundle provides easy reCAPTCHA form field integration

  Sources   Download

MIT

The Requires

 

recaptcha