Blue Horn

Symfony Framework

How to add a captcha field in Symfony 1.1

February 5, 2009 by Sid in Symfony Framework with 5 Comments

Step by step on how to add a captcha field to a Symfony 1.1 form.

1. Install sfFormExtraPlugin:

$ symfony plugin:install sfFormExtraPlugin
$ symfony cache:clear

2. Register for public and private keys at It’s free! Note that when you’re creating keys, it’s better to tick the ‘Enable this key on all domains (global key)’. This will allow you to use it anywhere. But of course it would be a good idea to untick this once your website goes live.

3. Add the captcha widget and validator to your form class:

// widget:
‘captcha’ => new sfWidgetFormReCaptcha(array(‘public_key’ => ‘your public key here’))
// validator:
‘captcha’ => new sfValidatorReCaptcha(array(‘private_key’ => ‘your private key here’))

4. And lastly, the way you bind the form values is quite different now. Instead of:


with the captcha, now you have to do:

$captcha = array(
‘recaptcha_challenge_field’ => $request->getParameter(‘recaptcha_challenge_field’),
‘recaptcha_response_field’  => $request->getParameter(‘recaptcha_response_field’),
$form->bind(array_merge($values, array(‘captcha’ => $captcha)));

That’s it! :-)

These information are kind of available in sfWidgetFormReCaptcha.class.php and sfValidatorReCaptcha.class.php, so I would recommend go and look there too.

Tagged , ,


  1. jayzDecember 14, 2009 at 11:53 am

    This doesn’t work for me at all. I am using symfony 1.3. Could you please explain what is $values in part 4.

  2. SidDecember 14, 2009 at 12:00 pm


    Hi Jayz,

    First of all, this is a guide for Symfony 1.1, not 1.3. I have not tested it on other versions of Symfony. So I don’t know if it’s working on 1.3.

    Secondly, this is not a guide for Admin/CRUD generated forms. This is a guide for those who build their forms manually using sfForm.

    But to answer your question:

    $values is the tainted values, the values from the request object.

    For example:

    $values = $request->getParameters(‘user’);

    Merry Christmas and happy coding :)

  3. Erman TaylanJanuary 28, 2011 at 6:01 am

    thanks man. its clean and right.

  4. mystertyFebruary 4, 2011 at 6:29 am

    Thancks, it’s really usefull. ;)

  5. RoopendraJune 13, 2012 at 10:40 pm

    Thanks a lot . It’s so simple :)

Leave a reply

Your email address will not be published. Required fields are marked *


5 × two =

My Projects
Restaurant Websites