2017 © Pedro PelĂĄez
 

symfony-bundle recaptcha-bundle

This bundle provides an easy reCAPTCHA form field integration into a Symfony Project

image

vihuvac/recaptcha-bundle

This bundle provides an easy reCAPTCHA form field integration into a Symfony Project

  • Wednesday, January 17, 2018
  • by vihuvac
  • Repository
  • 1 Watchers
  • 9 Stars
  • 13,383 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 8 Forks
  • 2 Open issues
  • 16 Versions
  • 16 % Grown

The README.md

VihuvacRecaptchaBundle

:warning: DEPRECATED:, (*1)

Unfortunately I want to inform this bundle is getting deprecated, I recommend using EWZRecaptchaBundle instead. Sorry for the inconvenience. :pensive:, (*2)


This bundle provides easy reCAPTCHA form field for Symfony in order to protect your website from spam and abuse., (*3)

Latest Stable Version Latest Unstable Version Gitter License, (*4)

Total Downloads Monthly Downloads Daily Downloads, (*5)

Branch Travis Coveralls
master Build Status Coverage Status

Installation

Step 1: Using composer and enable the Bundle

To install the bundle via composer, just run from the command line (terminal):, (*6)

$ composer require vihuvac/recaptcha-bundle

Composer will automatically download all the 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:, (*7)

// app/AppKernel.php

 **NOTE**:
>
> This bundle uses a secure API (**HTTPS Protocol**). **Google API** solves the requests by the Browser (**Client**).
>
> The ```site_key``` parameter is the same than the ```public_key``` parameter and the ```secret_key``` parameter is the same than the ```private_key``` parameter (parameters used in the previous versions).

You can easily **enable** and **disable** the reCAPTCHA feature using any one of the booleans ```true``` or ```false``` through the **enabled** parameter, e.g:

```yaml
# app/config/config.yml

vihuvac_recaptcha:
    // ...
    enabled: true
```

If you want to use the language used by the locale request as the language for the reCAPTCHA, you must activate the resolver (deactivated by default):

```yaml
# app/config/config.yml

vihuvac_recaptcha:
    // ...
    locale_from_request: true
```

You can load the reCAPTCHA using the Ajax API (**optional**):

```yaml
# app/config/config.yml

vihuvac_recaptcha:
    // ...
    ajax: true
```

Additionally you can add HTTP Proxy configuration (**optional**):

```yaml
# app/config/config.yml

vihuvac_recaptcha:
    // ...
    host: proxy.your-domain.com
    port: 3128
    auth: proxy_username:proxy_password
```
In case you have turned off the domain name checking on reCAPTCHA's end, you'll need to check the origin of the response by enabling the ```verify_host``` option:

```yaml
# app/config/config.yml

vihuvac_recaptcha:
    // ...
    verify_host: true
```

Congratulations! You're ready!

## Basic Usage

When creating a new form class add the following line to create the field:

##### Symfony and PHP Reference

Package  | Symfony              | PHP                |
-------- | -------------------- | ------------------ |
Version  | **~2.3** to **~2.7** | **5.3** to **5.6** |

```php
add("recaptcha", "vihuvac_recaptcha");
    // ...
}
```

##### Symfony and PHP Reference

Package  | Symfony              | PHP                |
-------- | -------------------- | ------------------ |
Version  | **~2.8**             | **5.5** to **7.1** |
Version  | **~3.0** to **~3.3** | **5.5** to **7.1** |

> **Note**:
>
> To denote the form type, you have to use the fully qualified class name - like ```TextType::class``` in PHP 5.5+ or ```Symfony\Component\Form\Extension\Core\Type\TextType```.
> Before Symfony 2.8, you could use an alias for each type like ```text``` or ```date```.
> The old alias syntax will still work until Symfony 3.0. For more details, see the [2.8 UPGRADE Log](https://github.com/symfony/symfony/blob/2.8/UPGRADE-2.8.md#form "2.8 UPGRADE Log - Official Doc").

```php
add("recaptcha", RecaptchaType::class);
    // ...
}
```

You can pass extra options to reCAPTCHA with the ```attr > options``` option, e.g:

```php
add("recaptcha", RecaptchaType::class, array(
        "attr" => array(
            "options" => array(
                "theme" => "light",
                "type"  => "audio",
                "size"  => "normal",
                "defer" => false,   // Set true if you want to use the Ajax API.
                "async" => false    // Set true if you want to use the Ajax API.
            )
        )
    ));
    // ...
}
```

reCAPTCHA tag attributes and render parameters:

| Tag attribute         | Render parameter |     Value        | Default |                Description               |
| --------------------- | :--------------: | :--------------: | :-----: | ---------------------------------------: |
| data-theme            | theme            | dark / light     | light   | Optional. The color theme of the widget. |
| data-type             | type             | audio / image    | image   | Optional. The type of CAPTCHA to serve.  |
| data-size             | size             | compact / normal | normal  | Optional. The size of the widget.        |
| data-expired-callback | expiredCallback  |                  |         | Optional. The name of your callback function to be executed when the recaptcha response expires and the user needs to solve a new CAPTCHA. |
|                       | defer            | true / false     | false   | Optional for the Ajax API.               |
|                       | async            | true / false     | false   | Optional for the Ajax API.               |

Support Google's Invisible reCAPTCHA! It's super easy:

```php
add("recaptcha", RecaptchaType::class, array(
        "attr" => array(
            "options" => array(
                "theme"    => "light",
                "type"     => "image",
                "size"     => "invisible",          // Set size to the invisible reCAPTCHA.
                "defer"    => false,                // Set true if you are using the Ajax API.
                "async"    => false,                // Set true if you are using the Ajax API.
                "callback" => "onReCaptchaSuccess", // Callback will be set by default if it's not defined (along with JS function that validates the form on success).
                "bind"     => "buttonSubmit",       // This is the form submit button id (html attribute).
                // ...
             )
        )
    ));
    // ...
}
```

> **Note**:
> If you use the pre-defined callback, you would need to add ```recaptcha-form``` class to your ```
``` tag. If you need to configure the language for the reCAPTCHA depending on your site language (ideal for multi-language sites) you can pass the language with the "language" option: ```php add("recaptcha", RecaptchaType::class, array( "language" => "en", // ... )); // ... } ``` To validate the field use: ```php false``` then the annotation will not work. You have to also set ```constraints```: ```php add("recaptcha", RecaptchaType::class, array( "attr" => array( "options" => array( "theme" => "light", "type" => "audio", "size" => "normal" ) ), "mapped" => false, "constraints" => array( new RecaptchaTrue() ) )); // ... ``` Cool! The form template resource is now auto registered via container extension. However, you can always implement your own custom form widget: **PHP**: ```php setTheme($form, array("VihuvacRecaptchaBundle:Form")) ?> widget($form["recaptcha"], array( "attr" => array( "options" => array( "theme" => "light", "type" => "audio", "size" => "normal" ) ) )) ?>

Twig:, (*8)

{% form_theme form "VihuvacRecaptchaBundle:Form:vihuvac_recaptcha_widget.html.twig" %}

{{
    form_widget(
        form.recaptcha, {
            "attr": {
                "options": {
                    "theme": "light",
                    "type": "audio",
                    "size": "normal"
                },
            }
        }
    )
}}

If you are not using a form, you can still implement the reCAPTCHA field using JavaScript:, (*9)

PHP:, (*10)

<div id="recaptcha-container"></div>
<script type="text/javascript">
    $(document).ready(function() {
        $.getScript("<?php echo \Vihuvac\Bundle\RecaptchaBundle\Form\Type\VihuvacRecaptchaType::RECAPTCHA_API_JS_SERVER ?>", function() {
            Recaptcha.create("<?php echo $form['recaptcha']->get('site_key') ?>", "recaptcha-container", {
                theme: "light",
                type: "audio",
                "size": "normal"
            });
        });
    };
</script>

Twig:, (*11)

<div id="recaptcha-container"></div>
<script type="text/javascript">
    $(document).ready(function() {
        $.getScript("{{ constant('\\Vihuvac\\Bundle\\RecaptchaBundle\\Form\\Type\\VihuvacRecaptchaType::RECAPTCHA_API_JS_SERVER') }}", function() {
            Recaptcha.create("{{ form.recaptcha.get('site_key') }}", "recaptcha-container", {
                theme: "light",
                type: "audio",
                "size": "normal"
            });
        });
    });
</script>

Customization:, (*12)

If you want to use a custom theme, put your chunk of code before setting the theme:, (*13)



Incorrect please try again
Enter the words above: Enter the numbers you hear:
{% form_theme form "VihuvacRecaptchaBundle:Form:vihuvac_recaptcha_widget.html.twig %} {{ form_widget( form.recaptcha, { "attr": { "options" : { "theme" : "custom", }, } } ) }}

Further reading: Google Official Doc., (*14)

Tests

Execute this command to run tests:, (*15)

$ cd recaptcha-bundle/
$ ./vendor/bin/phpunit

Note: If you are running tests only and within the bundle, as first step you should run composer install in order to install the required dependencies. Then you'll be able to run the tests!, (*16)

The Versions

17/01 2018

dev-master

9999999-dev https://github.com/vihuvac/recaptcha-bundle

This bundle provides an easy reCAPTCHA form field integration into a Symfony Project

  Sources   Download

MIT

The Requires

 

The Development Requires

google recaptcha symfony bundle vihuvac

17/01 2018

v2.2.0

2.2.0.0 https://github.com/vihuvac/recaptcha-bundle

This bundle provides an easy reCAPTCHA form field integration into a Symfony Project

  Sources   Download

MIT

The Requires

 

The Development Requires

google recaptcha symfony bundle vihuvac

22/04 2017

v2.1.8

2.1.8.0 https://github.com/vihuvac/recaptcha-bundle

This bundle provides an easy reCAPTCHA form field integration into a Symfony Project

  Sources   Download

MIT

The Requires

 

The Development Requires

google recaptcha symfony bundle vihuvac

09/04 2017

v2.1.7

2.1.7.0 https://github.com/vihuvac/recaptcha-bundle

This bundle provides an easy reCAPTCHA form field integration into a Symfony Project

  Sources   Download

MIT

The Requires

 

The Development Requires

google recaptcha symfony bundle vihuvac

26/02 2017

v2.1.6

2.1.6.0 https://github.com/vihuvac/recaptcha-bundle

This bundle provides an easy reCAPTCHA form field integration into a Symfony Project

  Sources   Download

MIT

The Requires

 

The Development Requires

google recaptcha symfony bundle vihuvac

02/02 2017

v2.1.5

2.1.5.0 https://github.com/vihuvac/recaptcha-bundle

This bundle provides an easy reCAPTCHA form field integration into a Symfony Project

  Sources   Download

MIT

The Requires

 

google recaptcha symfony bundle vihuvac

29/09 2016

v2.1.4

2.1.4.0 https://github.com/vihuvac/recaptcha-bundle

This bundle provides an easy reCAPTCHA form field integration into a Symfony Project

  Sources   Download

MIT

The Requires

 

google recaptcha symfony bundle vihuvac

11/08 2016

v2.1.3

2.1.3.0 https://github.com/vihuvac/recaptcha-bundle

This bundle provides an easy reCAPTCHA form field integration into a Symfony Project

  Sources   Download

MIT

The Requires

 

google recaptcha symfony bundle vihuvac

06/08 2016

v2.1.2

2.1.2.0 https://github.com/vihuvac/recaptcha-bundle

This bundle provides an easy reCAPTCHA form field integration into a Symfony Project

  Sources   Download

MIT

The Requires

 

google recaptcha symfony bundle vihuvac

05/06 2016

v2.1.1

2.1.1.0 https://github.com/vihuvac/recaptcha-bundle.git

This bundle provides an easy reCAPTCHA form field integration into a Symfony Project

  Sources   Download

MIT

The Requires

 

google recaptcha symfony bundle vihuvac

04/06 2016

v2.1.0

2.1.0.0 https://github.com/vihuvac/recaptcha-bundle.git

This bundle provides an easy reCAPTCHA form field integration into a Symfony Project

  Sources   Download

MIT

The Requires

 

google recaptcha symfony bundle vihuvac

01/03 2016

v2.0.2

2.0.2.0 https://github.com/vihuvac/recaptcha-bundle.git

This bundle provides an easy reCAPTCHA form field integration into a Symfony Project

  Sources   Download

MIT

google recaptcha symfony bundle vihuvac

08/06 2015

v2.0.1

2.0.1.0 https://github.com/vihuvac/recaptcha-bundle.git

This bundle provides an easy reCAPTCHA form field integration into a Symfony Project

  Sources   Download

MIT

The Requires

 

google recaptcha symfony bundle vihuvac

06/06 2015

v2.0.0

2.0.0.0 https://github.com/vihuvac/recaptcha-bundle.git

This bundle provides an easy reCAPTCHA form field integration into a Symfony Project

  Sources   Download

MIT

The Requires

 

google recaptcha symfony bundle vihuvac

05/06 2015

v1.0.1

1.0.1.0 https://github.com/vihuvac/recaptcha-bundle.git

This bundle provides an easy reCAPTCHA form field integration into a Symfony Project

  Sources   Download

MIT

The Requires

 

google recaptcha symfony bundle vihuvac

02/06 2014

v1.0.0

1.0.0.0 https://github.com/vihuvac/GoogleRecaptchaBundle

This bundle provides an easy reCAPTCHA form field integration into a Symfony Project

  Sources   Download

MIT

The Requires

 

google recaptcha symfony bundle