Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andanteproject/recaptcha-bundle
A Symfony Bundle to easily integrate Google reCAPTCHA into Symfony Form
https://github.com/andanteproject/recaptcha-bundle
google-recaptcha google-recaptcha-v2 php php7 php74 symfony symfony-bundle symfony-form symfony-formtype
Last synced: 2 months ago
JSON representation
A Symfony Bundle to easily integrate Google reCAPTCHA into Symfony Form
- Host: GitHub
- URL: https://github.com/andanteproject/recaptcha-bundle
- Owner: andanteproject
- License: mit
- Created: 2021-02-25T11:49:10.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-12-17T09:40:04.000Z (about 3 years ago)
- Last Synced: 2024-09-29T20:01:29.994Z (3 months ago)
- Topics: google-recaptcha, google-recaptcha-v2, php, php7, php74, symfony, symfony-bundle, symfony-form, symfony-formtype
- Language: PHP
- Homepage:
- Size: 21.5 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![Andante Project Logo](https://github.com/andanteproject/recaptcha-bundle/blob/main/andanteproject-logo.png?raw=true)
# Google ReCAPTCHA Bundle
#### Symfony Bundle - [AndanteProject](https://github.com/andanteproject)
[![Latest Version](https://img.shields.io/github/release/andanteproject/recaptcha-bundle.svg)](https://github.com/andanteproject/recaptcha-bundle/releases)
![Github actions](https://github.com/andanteproject/recaptcha-bundle/actions/workflows/workflow.yml/badge.svg?branch=main)
![Framework](https://img.shields.io/badge/Symfony-4.x|5.x|6.x-informational?Style=flat&logo=symfony)
![Php7](https://img.shields.io/badge/PHP-%207.4|8.x-informational?style=flat&logo=php)
![PhpStan](https://img.shields.io/badge/PHPStan-Level%208-syccess?style=flat&logo=php)A Symfony Bundle to easily integrate [Google reCAPTCHA](https://www.google.com/recaptcha/) into [Symfony Form](https://symfony.com/doc/current/forms.html).
## Requirements
Symfony 4.x-6.x and PHP 7.4-8.x.## Install
Via [Composer](https://getcomposer.org/):
```bash
$ composer require andanteproject/recaptcha-bundle
```## Features
- Add [Google reCAPTCHA](https://www.google.com/recaptcha/) to your [Symfony Form](https://symfony.com/doc/current/forms.html) just like you do with every other `FormType`;
- Works like magic ✨.## Install
After [install](#install), make sure you have the bundle registered in your symfony bundles list (`config/bundles.php`):
```php
return [
/// bundles...
Andante\ReCaptchaBundle\AndanteReCaptchaBundle::class => ['all' => true],
/// bundles...
];
```
This should have been done automagically if you are using [Symfony Flex](https://flex.symfony.com). Otherwise, just register it by yourself.## Configuration
Create a new `andante_re_captcha.yaml` configuration file and sets [Google ReCAPTCHA v2 `secret` and `site_key`](http://www.google.com/recaptcha/admin).
```yaml
andante_re_captcha:
secret: 'put_here_your_google_recaptcha_v2_secret'
site_key: 'put_here_your_google_recaptcha_v2_site_key'
```
### Dev/test environment Configuration
**Please note:** If you don't want to be annoyed by recaptcha in your development/test environment, just use `secret key` and `site key` you can find in this [Google ReCAPTCHA documentation page](https://developers.google.com/recaptcha/docs/faq#id-like-to-run-automated-tests-with-recaptcha.-what-should-i-do).
Furthermore, you can create a `test` configuration to disable `Andante\ReCaptchaBundle\Validator\Constraint\ReCaptchaValidator` in `test` environment:
```yaml
andante_re_captcha:
enable_validation: false #default: true
```## Usage
After this, you can add `Andante\ReCaptchaBundle\Form\ReCaptchaType` Form type in your forms like you always do with other types.
```php
add('recaptcha', ReCaptchaType::class);
}
}
```
**Done!** 🎉You also have 2 options to change ReCAPTCHA _theme_ or _size_.
```php
$builder->add('recaptcha', ReCaptchaType::class, [
'theme' => 'dark', // default is "light"
'size' => 'compact' // default is "normal"
]);
```
Using the option `'theme'` => `'dark'` is especially useful if your app has a dark mode.## How to change validation process
Validation is handled by `Andante\ReCaptchaBundle\Validator\Constraint\ReCaptchaValidator`, which is a default constraint inside `ReCaptchaType` options.
If you want to replace it with your own or disable it for whatever reason, just empty/replace form type `constraints` option.
```php
$builder->add('recaptcha', ReCaptchaType::class, [
'constraints' => [
// Default value is Constraints\NotBlank + Constraint\Recaptcha
]
]);
```Built with love ❤️ by [AndanteProject](https://github.com/andanteproject) team.