robole/sulu-form-captcha-bundle

Extension for SuluFormBundle that adds third-party captcha providers

v1.0.1 2025-02-17 13:12 UTC

This package is auto-updated.

Last update: 2025-02-17 13:15:51 UTC


README

GitHub release Supports Sulu 2.6 or later

SuluFormCaptchaBundle

Extension for SuluFormBundle that adds third-party captcha providers.

Installation

This bundle requires PHP 8.2 or later.

  1. Open a command console, enter your project directory and run:
composer require robole/sulu-form-captcha-bundle

If not automagically done, add the bundle to your config/bundles.php file:

return [
    //...
    Robole\SuluFormCaptchaBundle\SuluFormCaptchaBundle::class => ['all' => true],
];
  1. Install and configure one or mutiple captcha providers from below. Once installed, each provider can be selected in the Sulu form editor.

Use with Cloudflare Turnstile

  1. Install PixelOpen Cloudflare Turnstile Bundle:
composer require pixelopen/cloudflare-turnstile-bundle

Then, enable the bundle by adding it to the list of registered bundles in the config/bundles.php file of your project:

return [
    //...
    PixelOpen\CloudflareTurnstileBundle\PixelOpenCloudflareTurnstileBundle::class => ['all' => true]
];
  1. Visit Cloudfare, create a site key and secret key, save the keys to .env and link via service configuration in config/packages/pixel_open_cloudlflare_turnstile.yaml:
pixel_open_cloudflare_turnstile:
    key: "%env(TURNSTILE_KEY)%"
    secret: "%env(TURNSTILE_SECRET)%"

For more information, refer to the bundle repository.

Use with Gregwar Captcha

  1. Install Gregwar CaptchaBundle:
composer require gregwar/captcha-bundle

Then, enable the bundle by adding it to the list of registered bundles in the config/bundles.php file of your project:

return [
    //...
    Gregwar\CaptchaBundle\GregwarCaptchaBundle::class => ['all' => true]
];
  1. Customize the global bundle configuration in config/packages/gregwar_captcha.yaml:
gregwar_captcha:
  width: 160
  height: 50

For more information on configuration and form theming, refer to the bundle repository.

Use with Friendly Captcha

Attention: This bundle currently only supports Symfony 6 and Friendly Captcha v1! Both, a PR for Symfony 7 compatibility and an information request about the future bundle development can be found in the bundle repository.

  1. Install CORS Friendly Captcha Bundle:
composer require cors/friendly-captcha-bundle

Then, enable the bundle by adding it to the list of registered bundles in the config/bundles.php file of your project:

return [
    //...
    CORS\Bundle\FriendlyCaptchaBundle\CORSFriendlyCaptchaBundle::class => ['all' => true],
];
  1. Visit Friendly Captcha, create a site key and secret key, save the keys to .env and link via service configuration in config/packages/cors_friendly_captcha.yaml:
cors_friendly_captcha:
    sitekey: "%env(FRIENDLY_SITEKEY)%"
    secret: "%env(FRIENDLY_SECRET)%"
    use_eu_endpoints: true
  1. Import the widget via npm in your application or load from CDN, e.g. in base.html.twig:
  <script type="module" src="https://cdn.jsdelivr.net/npm/friendly-challenge@0.9.18/widget.module.min.js" async defer></script>
  <script nomodule src="https://cdn.jsdelivr.net/npm/friendly-challenge@0.9.18/widget.min.js" async defer></script>

For more information, refer to the bundle repository.

Theming

This bundle provides a minimal theme.html.twig which extends @SuluForm/themes/basic.html.twig. Use it like this:

<body>
    {% 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 %}
</body>

To customize the default blocks (or to customize the default blocks provided by SuluFormBundle), extend @SuluFormCaptcha/theme.html.twig similar as described in SuluFormBundle theming.md.

Scripts

  • To check the coding standards, run:

    composer php-cs

  • To apply coding standards, run:

    composer php-cs-fix