https://github.com/pixel-open/cloudflare-turnstile-bundle
A simple package to help integrate Cloudflare Turnstile on Symfony Form.
https://github.com/pixel-open/cloudflare-turnstile-bundle
cloudflare-turnstile recaptcha symfony-bundle
Last synced: 5 months ago
JSON representation
A simple package to help integrate Cloudflare Turnstile on Symfony Form.
- Host: GitHub
- URL: https://github.com/pixel-open/cloudflare-turnstile-bundle
- Owner: Pixel-Open
- License: mit
- Created: 2022-10-01T10:34:56.000Z (about 3 years ago)
- Default Branch: develop
- Last Pushed: 2024-09-30T15:44:13.000Z (about 1 year ago)
- Last Synced: 2025-05-04T06:17:16.114Z (5 months ago)
- Topics: cloudflare-turnstile, recaptcha, symfony-bundle
- Language: PHP
- Homepage: https://pixel-open.org/projects/symfony-bundle-cloudflare-turnstile/
- Size: 77.1 KB
- Stars: 28
- Watchers: 1
- Forks: 6
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: Changelog.md
- License: LICENSE
Awesome Lists containing this project
README
A simple package to help integrate Cloudflare Turnstile on Symfony Form.
======================[](https://php.net/)
[](https://symfony.com)
[](https://github.com/Pixel-Open/cloudflare-turnstile-bundle/releases)
[](https://sonarcloud.io/summary/new_code?id=Pixel-Open_cloudflare-turnstile-bundle)This packages provides helper for setting up and validating Cloudflare Turnstile CAPTCHA responses.

## Installation
You can install the package via Composer:
```bash
composer require pixelopen/cloudflare-turnstile-bundle
```Add bundle into config/bundles.php file :
```php
PixelOpen\CloudflareTurnstileBundle\PixelOpenCloudflareTurnstileBundle::class => ['all' => true]
```
Add a config file into config/packages/pixel_open_cloudflare_turnstile.yaml :```yaml
pixel_open_cloudflare_turnstile:
key: '%env(TURNSTILE_KEY)%'
secret: '%env(TURNSTILE_SECRET)%'
enable : true
```Visit Cloudflare to create your site key and secret key and add them to your `.env` file.
```
TURNSTILE_KEY="1x00000000000000000000AA"
TURNSTILE_SECRET="2x0000000000000000000000000000000AA"
```### Use with your Symfony Form
Create a form type and insert an Turnstile Type to add a Cloudflare Turnstile :
```php
add('name', TextType::class, ['label' => false, 'attr' => ['placeholder' => 'name']])
->add('message', TextareaType::class, ['label' => false, 'attr' => ['placeholder' => 'message']])
->add('security', TurnstileType::class, ['attr' => ['data-action' => 'contact', 'data-theme' => 'dark'], 'label' => false])
->add('submit', SubmitType::class)
;
}public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Contact::class,
]);
}
}
```### Testing
Use the following sitekeys and secret keys for testing purposes:
**Sitekey**
| Sitekey | Description |
|--------------------------|---------------------------------|
| 1x00000000000000000000AA | Always passes |
| 2x00000000000000000000AB | Always blocks |
| 3x00000000000000000000FF | Forces an interactive challenge |**Secret key**
| Secret key | Description |
|-------------------------------------|--------------------------------------|
| 1x0000000000000000000000000000000AA | Always passes |
| 2x0000000000000000000000000000000AA | Always fails |
| 3x0000000000000000000000000000000AA | Yields a "token already spent" error |## Todo
+ Add phpunit to test field ~~and validator~~
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.