### Install SuluFormCaptchaBundle
Source: https://github.com/robole-dev/sulu-form-captcha-bundle/blob/main/README.md
Installs the SuluFormCaptchaBundle using Composer. This bundle requires PHP 8.2 or later and extends the functionality of the SuluFormBundle.
```console
composer require robole/sulu-form-captcha-bundle
```
--------------------------------
### Install AltchaBundle
Source: https://github.com/robole-dev/sulu-form-captcha-bundle/blob/main/README.md
Installs the AltchaBundle using Composer. This bundle integrates the ALTCHA (Anti-Lottery CAPTCHA) service into the Sulu form system.
```console
composer require tito10047/altcha-bundle
```
--------------------------------
### Install Gregwar Captcha Bundle
Source: https://github.com/robole-dev/sulu-form-captcha-bundle/blob/main/README.md
Installs the Gregwar CaptchaBundle using Composer. This bundle provides a simple captcha solution that generates image-based challenges.
```console
composer require gregwar/captcha-bundle
```
--------------------------------
### Integrate ALTCHA Proof-of-Work CAPTCHA System (PHP)
Source: https://context7.com/robole-dev/sulu-form-captcha-bundle/llms.txt
This code demonstrates how to integrate the ALTCHA CAPTCHA system into Sulu forms. It outlines the steps for installing the necessary bundle, registering it in `config/bundles.php`, and following the bundle's documentation for specific ALTCHA configurations. The `AltchaCaptchaType` class facilitates the integration.
```php
['all' => true],
];
// 3. Follow ALTCHA configuration as per bundle documentation
// (Typically involves setting algorithm, complexity, etc.)
// The AltchaCaptchaType handles integration:
namespace Robole\SuluFormCaptchaBundle\Form\Types;
class AltchaCaptchaType implements FormFieldTypeInterface
{
public function build(FormBuilderInterface $builder, FormField $field, string $locale, array $options): void
{
$builder->add($field->getKey(), \Tito10047\AltchaBundle\Type\AltchaType::class, $options);
}
}
// Now available in Sulu admin as "Captcha (ALTCHA)"
```
--------------------------------
### Install CORS Friendly Captcha Bundle
Source: https://github.com/robole-dev/sulu-form-captcha-bundle/blob/main/README.md
Installs the CORS Friendly Captcha Bundle using Composer. Note: This bundle currently only supports Friendly Captcha v1.
```console
composer require cors/friendly-captcha-bundle
```
--------------------------------
### Integrate Gregwar Captcha
Source: https://context7.com/robole-dev/sulu-form-captcha-bundle/llms.txt
This snippet demonstrates the integration of Gregwar Captcha, an image-based CAPTCHA solution. It covers installing the necessary bundle, registering it, configuring its appearance, and the form field type for its use in Sulu forms.
```php
['all' => true],
];
// 3. Configure appearance in config/packages/gregwar_captcha.yaml
// gregwar_captcha:
// width: 160
// height: 50
// length: 5
// quality: 90
// charset: 'abcdefghijklmnpqrstuvwxyz123456789'
// The GregwarCaptchaType handles integration:
namespace Robole\SuluFormCaptchaBundle\Form\Types;
use Sulu\Bundle\FormBundle\Dynamic\FormFieldTypeInterface;
use Sulu\Bundle\FormBundle\Entity\FormField;
use Symfony\Component\Form\FormBuilderInterface;
class GregwarCaptchaType implements FormFieldTypeInterface
{
public function build(FormBuilderInterface $builder, FormField $field, string $locale, array $options): void
{
$builder->add($field->getKey(), \Gregwar\CaptchaBundle\Type\CaptchaType::class, $options);
}
}
// Twig template rendering (automatic via theme.html.twig):
// {% block captcha_widget %}
// {{ form_label(form, label|default())
//
// {{ form_widget(form) }}
// {% endblock %}
// Now available in Sulu admin as "Captcha (Gregwar)"
```
--------------------------------
### Install Cloudflare Turnstile Bundle
Source: https://github.com/robole-dev/sulu-form-captcha-bundle/blob/main/README.md
Installs the PixelOpen Cloudflare Turnstile Bundle using Composer. This bundle integrates Cloudflare's Turnstile captcha service into the Sulu form system.
```console
composer require pixelopen/cloudflare-turnstile-bundle
```
--------------------------------
### Integrate Friendly Captcha v1 with EU Endpoint Support (PHP)
Source: https://context7.com/robole-dev/sulu-form-captcha-bundle/llms.txt
This snippet shows how to integrate Friendly Captcha v1 into a Sulu form. It includes installation instructions, bundle registration, configuration for sitekey, secret, and EU endpoints, and how to load the widget in Twig. The `FriendlyCaptchaType` class handles the form integration, and a Twig block is provided for rendering the CAPTCHA widget.
```php
['all' => true],
];
// 3. Configure in config/packages/cors_friendly_captcha.yaml
// cors_friendly_captcha:
// sitekey: "%env(FRIENDLY_SITEKEY)%"
// secret: "%env(FRIENDLY_SECRET)%"
// use_eu_endpoints: true
// 4. Add to .env
// FRIENDLY_SITEKEY=your_site_key
// FRIENDLY_SECRET=your_secret_key
// 5. Load widget in base.html.twig
//
//
// The FriendlyCaptchaType handles form integration:
namespace Robole\SuluFormCaptchaBundle\Form\Types;
class FriendlyCaptchaType implements FormFieldTypeInterface
{
public function build(FormBuilderInterface $builder, FormField $field, string $locale, array $options): void
{
$options['constraints'] = new \CORS\Bundle\FriendlyCaptchaBundle\Validator\FriendlyCaptchaValid();
$builder->add($field->getKey(), \CORS\Bundle\FriendlyCaptchaBundle\Form\Type\FriendlyCaptchaType::class, $options);
}
}
// Twig rendering block (theme.html.twig):
// {%- block cors_friendly_catcha_type_row -%}
// {{ form_label(form, label|default()) }}
//
// {%- endblock -%}
// Now available in Sulu admin as "Captcha (Friendly Captcha)"
```
--------------------------------
### Dynamically Load CAPTCHA Providers Based on Dependencies (PHP)
Source: https://context7.com/robole-dev/sulu-form-captcha-bundle/llms.txt
PHP code from the SuluFormCaptchaBundle's main class demonstrating dynamic loading of CAPTCHA providers. It checks for the existence of specific CAPTCHA provider bundle classes before loading their respective XML service configurations, allowing for optional installations.
```php
load('type_turnstile.xml');
}
if (class_exists(\Gregwar\CaptchaBundle\Type\CaptchaType::class)) {
$loader->load('type_gregwar.xml');
}
if (class_exists(\CORS\Bundle\FriendlyCaptchaBundle\Form\Type\FriendlyCaptchaType::class)) {
$loader->load('type_friendly.xml');
}
if (class_exists(\Tito10047\AltchaBundle\Type\AltchaType::class)) {
$loader->load('type_altcha.xml');
}
}
public function prependExtension(ContainerConfigurator $containerConfigurator, ContainerBuilder $containerBuilder): void
{
// Register translation paths
$containerBuilder->prependExtensionConfig('framework', [
'translator' => [
'paths' => [
'%kernel.project_dir%/vendor/robole/sulu-form-captcha-bundle/translations'
],
],
]);
// Register Twig namespace
$containerBuilder->prependExtensionConfig('twig', [
'paths' => [
'%kernel.project_dir%/vendor/robole/sulu-form-captcha-bundle/Resources/views' => 'SuluFormCaptcha'
],
]);
}
}
// This design allows installing only needed CAPTCHA providers
// Example: composer require robole/sulu-form-captcha-bundle pixelopen/cloudflare-turnstile-bundle
// Result: Only Turnstile will be available in Sulu admin
```
--------------------------------
### Integrate Cloudflare Turnstile CAPTCHA
Source: https://context7.com/robole-dev/sulu-form-captcha-bundle/llms.txt
This section details the integration of Cloudflare Turnstile CAPTCHA. It includes installation steps, bundle registration, configuration via environment variables and YAML, and the form field type implementation for seamless use within Sulu forms.
```php
['all' => true],
];
// 3. Configure in config/packages/pixel_open_cloudlflare_turnstile.yaml
// pixel_open_cloudflare_turnstile:
// key: "%env(TURNSTILE_KEY)%"
// secret: "%env(TURNSTILE_SECRET)%"
// 4. Add environment variables to .env
// TURNSTILE_KEY=your_site_key_here
// TURNSTILE_SECRET=your_secret_key_here
// The TurnstileCaptchaType class handles form field integration:
namespace Robole\SuluFormCaptchaBundle\Form\Types;
use Sulu\Bundle\FormBundle\Dynamic\FormFieldTypeInterface;
use Sulu\Bundle\FormBundle\Entity\FormField;
use Symfony\Component\Form\FormBuilderInterface;
class TurnstileCaptchaType implements FormFieldTypeInterface
{
public function build(FormBuilderInterface $builder, FormField $field, string $locale, array $options): void
{
$options['constraints'] = new \PixelOpen\CloudflareTurnstileBundle\Validator\CloudflareTurnstile();
$builder->add($field->getKey(), \PixelOpen\CloudflareTurnstileBundle\Type\TurnstileType::class, $options);
}
}
// Now available in Sulu admin form editor as "Captcha (Cloudfare Turnstile)"
```
--------------------------------
### Integrate CAPTCHA Rendering with Twig Themes (Twig)
Source: https://context7.com/robole-dev/sulu-form-captcha-bundle/llms.txt
Custom Twig template to extend Sulu Form Bundle theming for CAPTCHA rendering. It includes conditional rendering based on form submission status and an example of a custom theme extension for styling CAPTCHA widgets.
```twig
{# base.html.twig or your form template #}
{% if content.form %}
{% if app.request.get('send') != 'true' %}
{# Apply SuluFormCaptcha theme to render CAPTCHA fields properly #}
{% form_theme content.form '@SuluFormCaptcha/theme.html.twig' %}
{{ form(content.form) }}
{% else %}
{{ view.form.entity.successText|raw }}
{% endif %}
{% endif %}
{# Custom theme extension example #}
{# templates/forms/custom_captcha_theme.html.twig #}
{% extends '@SuluFormCaptcha/theme.html.twig' %}
{% block captcha_widget %}
{{ parent() }}
Please complete the CAPTCHA to verify you're human
{% endblock %}
{# Then use custom theme: #}
{# {% form_theme content.form 'forms/custom_captcha_theme.html.twig' %} #}
```
--------------------------------
### Register CAPTCHA Types as Sulu Form Fields (XML)
Source: https://context7.com/robole-dev/sulu-form-captcha-bundle/llms.txt
XML service configuration that registers CAPTCHA types as Sulu form fields. This example shows the registration for Turnstile CAPTCHA, with similar configurations for Gregwar, Friendly, and ALTCHA CAPTCHAs.
```xml
```
--------------------------------
### Enable AltchaBundle in bundles.php
Source: https://github.com/robole-dev/sulu-form-captcha-bundle/blob/main/README.md
Enables the AltchaBundle by adding it to the `config/bundles.php` file, making the ALTCHA captcha functionality available within the application.
```php
return [
//...
Tito10047\AltchaBundle\AltchaBundle::class => ['all' => true]
];
```
--------------------------------
### Configure Gregwar Captcha Bundle
Source: https://github.com/robole-dev/sulu-form-captcha-bundle/blob/main/README.md
Customizes the global configuration for the Gregwar Captcha Bundle in `config/packages/gregwar_captcha.yaml`, allowing adjustment of image dimensions.
```yaml
gregwar_captcha:
width: 160
height: 50
```
--------------------------------
### Enable Gregwar Captcha Bundle in bundles.php
Source: https://github.com/robole-dev/sulu-form-captcha-bundle/blob/main/README.md
Enables the Gregwar Captcha Bundle by adding it to the `config/bundles.php` file, making its captcha generation capabilities available to the application.
```php
return [
//...
Gregwar\CaptchaBundle\GregwarCaptchaBundle::class => ['all' => true]
];
```
--------------------------------
### Register SuluFormCaptchaBundle in Symfony
Source: https://context7.com/robole-dev/sulu-form-captcha-bundle/llms.txt
This snippet shows how to register the SuluFormCaptchaBundle in your Symfony application's configuration file. This is a standard Symfony bundle registration process.
```php
['all' => true],
];
// The bundle automatically:
// 1. Detects installed CAPTCHA provider bundles
// 2. Loads corresponding XML service configurations
// 3. Registers translation paths
// 4. Registers Twig namespace @SuluFormCaptcha
```
--------------------------------
### Configure Cloudflare Turnstile Keys
Source: https://github.com/robole-dev/sulu-form-captcha-bundle/blob/main/README.md
Configures the Cloudflare Turnstile service by specifying the site key and secret key in the `config/packages/pixel_open_cloudlflare_turnstile.yaml` file. These keys should be stored securely in environment variables.
```yaml
pixel_open_cloudflare_turnstile:
key: "%env(TURNSTILE_KEY)%"
secret: "%env(TURNSTILE_SECRET)%"
```
--------------------------------
### Enable Cloudflare Turnstile Bundle in bundles.php
Source: https://github.com/robole-dev/sulu-form-captcha-bundle/blob/main/README.md
Enables the Cloudflare Turnstile Bundle by adding it to the `config/bundles.php` file, allowing it to be used within the Symfony application.
```php
return [
//...
PixelOpen\CloudflareTurnstileBundle\PixelOpenCloudflareTurnstileBundle::class => ['all' => true]
];
```
--------------------------------
### Configure CORS Friendly Captcha Keys
Source: https://github.com/robole-dev/sulu-form-captcha-bundle/blob/main/README.md
Configures the CORS Friendly Captcha service in `config/packages/cors_friendly_captcha.yaml` using site and secret keys, and an option to use EU endpoints. Keys should be stored in environment variables.
```yaml
cors_friendly_captcha:
sitekey: "%env(FRIENDLY_SITEKEY)%"
secret: "%env(FRIENDLY_SECRET)%"
use_eu_endpoints: true
```
--------------------------------
### Enable SuluFormCaptchaBundle in bundles.php
Source: https://github.com/robole-dev/sulu-form-captcha-bundle/blob/main/README.md
Registers the SuluFormCaptchaBundle within the Symfony application's configuration by adding it to the `config/bundles.php` file.
```php
return [
//...
Robole\SuluFormCaptchaBundle\SuluFormCaptchaBundle::class => ['all' => true],
];
```
--------------------------------
### Provide Translation Support for CAPTCHA Fields (JSON)
Source: https://context7.com/robole-dev/sulu-form-captcha-bundle/llms.txt
JSON translation files for the admin interface and validation messages. This includes English translations for various CAPTCHA types and mentions that German translations and validation messages are also available. These are loaded automatically by the bundle.
```json
// translations/admin.en.json
{
"sulu_form_captcha_bundle.form.type.gregwar_captcha": "Captcha (Gregwar)",
"sulu_form_captcha_bundle.form.type.turnstile_captcha": "Captcha (Cloudfare Turnstile)",
"sulu_form_captcha_bundle.form.type.friendly_captcha": "Captcha (Friendly Captcha)",
"sulu_form_captcha_bundle.form.type.altcha_captcha": "Captcha (ALTCHA)"
}
// translations/admin.de.json - German translations also available
// translations/validators.de.json - Validation error messages
// translations/validators.en.json - English validation messages
// Translations are automatically loaded via SuluFormCaptchaBundle::prependExtension()
// which adds the translations directory to Symfony's translator paths
```
--------------------------------
### Enable CORS Friendly Captcha Bundle in bundles.php
Source: https://github.com/robole-dev/sulu-form-captcha-bundle/blob/main/README.md
Enables the CORS Friendly Captcha Bundle by adding it to the `config/bundles.php` file, integrating it with the Symfony application.
```php
return [
//...
CORS\Bundle\FriendlyCaptchaBundle\CORSFriendlyCaptchaBundle::class => ['all' => true],
];
```
--------------------------------
### Load Friendly Captcha Widget
Source: https://github.com/robole-dev/sulu-form-captcha-bundle/blob/main/README.md
Loads the Friendly Captcha widget script in a Twig template, using both module and nomodule versions for broader browser compatibility. This enables the Friendly Captcha widget on the form.
```twig
```
--------------------------------
### Configure CAPTCHA Field Properties in Sulu Admin (XML)
Source: https://context7.com/robole-dev/sulu-form-captcha-bundle/llms.txt
This XML snippet defines the properties for CAPTCHA fields within the Sulu admin interface. It specifies configuration options such as 'width' (with predefined choices like full, half, one-quarter) and an optional 'title' for the CAPTCHA field, allowing administrators to customize its appearance and behavior in forms.
```xml
sulu_form.width
sulu_form.width.full
sulu_form.width.half
sulu_form.width.one_quarter
sulu_form.title
```
--------------------------------
### Theme Sulu Form with Captcha
Source: https://github.com/robole-dev/sulu-form-captcha-bundle/blob/main/README.md
Applies the custom captcha theme to a Sulu form in a Twig template. This ensures that the captcha is rendered correctly within the form, and handles success messages.
```twig
{% if content.form %}
{% if app.request.get('send') != 'true' %}
{% form_theme content.form '@SuluFormCaptcha/theme.html.twig' %}
{{ form(content.form) }}
{% else %}
{{ view.form.entity.successText|raw }}
{% endif %}
{% endif %}
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.