mael / recaptcha-bundle
Google Recaptcha integration for Symfony and Twig (easy integration with Symfony Form)
Installs: 1 081
Dependents: 0
Suggesters: 1
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^7.1
- google/recaptcha: ^1.2
- symfony/config: ^4.4|^5.0
- symfony/dependency-injection: ^4.4|^5.0
- symfony/form: ^4.4|^5.0
- symfony/http-foundation: ^4.4|^5.0.7
- symfony/http-kernel: ^4.4|^5.0
- symfony/options-resolver: ^4.4|^5.0
- symfony/twig-pack: *
- symfony/validator: ^4.4|^5.0
Requires (Dev)
- phpunit/phpunit: ^9.1
This package is auto-updated.
Last update: 2024-11-13 01:22:29 UTC
README
MaelRecaptchaBundle is a bundle allowing the integration of Google Recaptcha on a Symfony project.
Available features
- Google ReCaptcha V2 (invisible) : ✅
- Google ReCaptcha V2 (checkbox) : ✅
- Google ReCaptcha V3 : ❌
Installation
It's very quick and easy, in 5 steps
- Install MaelRecaptchaBundle via composer
- Enable the bundle
- Generate you key and secret key
- Configure your key and secret key
- Use the Recaptcha in your forms
- Contributing
- License
Step 1 : Install MaelRecaptchaBundle via composer
Run the following command :
composer require mael/recaptcha-bundle
You can quickly configure this bundle by using symfony/flex
:
- Answer no for
google/recpatcha
- Answer yes for
mael/recaptcha-bundle
Step 2: Enable the bundle
Register bundle into config/bundles.php
<?php return [ Mael\MaelRecaptchaBundle\MaelRecaptchaBundle::class => ['all' => true], ];
Step 3: Generate your key and secret key
Go to the following link : http://www.google.com/recaptcha/admin
Setp 4: Configure your key and secret key
In you .env
file
Replace YOUR_RECAPTCHA_KEY
by your public key and YOUR_RECAPTCHA_SECRET
by your private key
MAEL_RECAPTCHA_KEY=YOUR_RECAPTCHA_KEY MAEL_RECAPTCHA_SECRET=YOUR_RECAPTCHA_SECRET
Step 5: Editing your form and your view
For Google ReCaptcha V2 (invisible)
To enable Recaptcha (invisible) protection on your form, you must use this type: MaelRecaptchaSubmitType::class
// For example ->add('captcha', MaelRecaptchaSubmitType::class, [ 'label' => 'Submit', 'constraints' => new MaelRecaptcha() ])
For the third parameter which is an array, you can add the constraint : MaelRecaptcha
Then, to complete the configuration of the invisible Recaptcha, in your twig file you need to add a id to your form
{{ form_start(your_form, {'attr': {'id': 'form-recaptcha'}}) }}
To finish, add 2 <script>
tags
Replace "id-of-your-form" by the class of your form add just above it
<script src="https://www.google.com/recaptcha/api.js" async defer></script> <script> function onSubmitCaptcha(token) { document.getElementById("class-of-your-form").submit(); } </script>
Warning, you cannot change the name of the JavaScript function.
For Google ReCaptcha V2 (checkbox)
To enable Recaptcha (checkbox) protection on your form, you must use this type: MaelRecaptchaCheckboxType::class
->add('captcha_checkvox', MaelRecaptchaCheckboxType::class, [ 'constraints' => new MaelRecaptcha() ])
For the third parameter which is an array, you can add the constraint : MaelRecaptcha
To finish, in your twig file add <script>
tag
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
Contributing
List of contribution HERE
You want contribute ? Fork this repertory and create a pull request after change
License
You can find the license in the root directory