BotDetect Symfony 3 CAPTCHA Integration Quickstart

1. Installing the BotDetect Symfony CaptchaBundle

Note: If you do not have Composer yet, you can install it by following the instructions on

If you have Git installed on your development machine, you should use the following installation procedure:

Step 1: Download CaptchaBundle using composer

Run the following command in your application's root directory:

Step 2: Enable the bundle (app/AppKernel.php):

$bundles = array(
  new Captcha\Bundle\CaptchaBundle\CaptchaBundle(),

Step 3: Import CaptchaBundle routing file (app/config/routing.yml):

  resource: "@CaptchaBundle/Resources/config/routing.yml"

2. Show a Captcha Challenge on the Form

Captcha configuration options (app/config/captcha.php):

<?php if (!class_exists('CaptchaConfiguration')) { return; }

// BotDetect PHP Captcha configuration options

return [
  // Captcha configuration for example page
  'ExampleCaptcha' => [
    'UserInputID' => 'captchaCode',
    'ImageWidth' => 250,
    'ImageHeight' => 50,


Adding the CaptchaType in your form:

$builder->add('captchaCode', 'Captcha\Bundle\CaptchaBundle\Form\Type\CaptchaType', array(
  'captchaConfig' => 'ExampleCaptcha'

3. Check User Input During Form Submission

Using the ValidCaptcha constraint to validate captcha code when a form is submitted:

namespace AppBundle\Entity;

use Captcha\Bundle\CaptchaBundle\Validator\Constraints as CaptchaAssert;

class Example
   * @CaptchaAssert\ValidCaptcha(
   *      message = "CAPTCHA validation failed, try again."
   * )
  protected $captchaCode;

  public function getCaptchaCode()
    return $this->captchaCode;

  public function setCaptchaCode($captchaCode)
    $this->captchaCode = $captchaCode;

In-Depth Symfony CAPTCHA Instructions and Explanations

Detailed Symfony Captcha instructions and explanations can be found in the Symfony 3 Captcha integration how to guide.

Other BotDetect PHP CAPTCHA Quickstarts

CakePHP 3 CAPTCHA Laravel 5.1 CAPTCHA CodeIgniter 3.0 CAPTCHA
CakePHP 2 CAPTCHA Laravel 5.0 CAPTCHA  
CodeIgniter 2.2 CAPTCHA Laravel 4.2 CAPTCHA  

BotDetect Symfony CAPTCHA System Requirements


Supported Symfony Versions:

  • Symfony 3.0.0+