An open API service indexing awesome lists of open source software.

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: 3 months ago
JSON representation

A simple package to help integrate Cloudflare Turnstile on Symfony Form.

Awesome Lists containing this project

README

          

A simple package to help integrate Cloudflare Turnstile on Symfony Form.
======================

[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%208.2-green)](https://php.net/)
[![Minimum Symfony Version](https://img.shields.io/badge/symfony-%3E%3D%205.4-green)](https://symfony.com)
[![GitHub release](https://img.shields.io/github/v/release/Pixel-Open/cloudflare-turnstile-bundle)](https://github.com/Pixel-Open/cloudflare-turnstile-bundle/releases)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=Pixel-Open_cloudflare-turnstile-bundle&metric=alert_status)](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.

![Cloudflare Turnstile for Symfony Form](screenshot.png)

## 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,
]);
}
}
```

### Use with PHP Attributes

Since Symfony 5.2, you can use the `CloudflareTurnstile` constraint as a PHP attribute directly on your DTO or entity properties:

```php