Download the PHP package vihuvac/recaptcha-bundle without Composer
On this page you can find all versions of the php package vihuvac/recaptcha-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vihuvac/recaptcha-bundle
More information about vihuvac/recaptcha-bundle
Files in vihuvac/recaptcha-bundle
Package recaptcha-bundle
Short Description This bundle provides an easy reCAPTCHA form field integration into a Symfony Project
License MIT
Homepage https://github.com/vihuvac/recaptcha-bundle
Informations about the package recaptcha-bundle
VihuvacRecaptchaBundle
:warning: DEPRECATED:
Unfortunately I want to inform this bundle is getting deprecated, I recommend using EWZRecaptchaBundle instead. Sorry for the inconvenience. :pensive:
This bundle provides easy reCAPTCHA form field for Symfony in order to protect your website from spam and abuse.
Branch | Travis | Coveralls |
---|---|---|
master |
Installation
Step 1: Using composer and enable the Bundle
To install the bundle via composer, just run from the command line (terminal):
Composer will automatically download all the required files, and install them for you. All that is left to do is to update your file, and register the new bundle:
Step 2: Configure the bundle
Add the following to your config file:
NOTE:
This bundle uses a secure API (HTTPS Protocol). Google API solves the requests by the Browser (Client).
The parameter is the same than the parameter and the parameter is the same than the parameter (parameters used in the previous versions).
You can easily enable and disable the reCAPTCHA feature using any one of the booleans or through the enabled parameter, e.g:
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):
You can load the reCAPTCHA using the Ajax API (optional):
Additionally you can add HTTP Proxy configuration (optional):
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 option:
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 |
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 in PHP 5.5+ or . Before Symfony 2.8, you could use an alias for each type like or . The old alias syntax will still work until Symfony 3.0. For more details, see the 2.8 UPGRADE Log.
You can pass extra options to reCAPTCHA with the option, e.g:
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:
Note: If you use the pre-defined callback, you would need to add 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:
To validate the field use:
Another method would consist to pass the validation constraints as an options of your FormType. This way, your data class contains only meaningful properties. If we take the example from above, the buildForm method would look like this. Please note that if you set then the annotation will not work. You have to also set :
Cool! The form template resource is now auto registered via container extension. However, you can always implement your own custom form widget:
PHP:
Twig:
If you are not using a form, you can still implement the reCAPTCHA field using JavaScript:
PHP:
Twig:
Customization:
If you want to use a custom theme, put your chunk of code before setting the theme:
Further reading: Google Official Doc.
Tests
Execute this command to run tests:
Note: If you are running tests only and within the bundle, as first step you should run in order to install the required dependencies. Then you'll be able to run the tests!