sfReCaptchaFormPlugin - 0.9.0

Ryan Weaver <ryan@thatsquality.com>

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


« Back to the Plugins Home

Signin


Forgot your password?
Create an account

Tools

Stats

advanced search
Information Readme Releases Changelog Contribute
Show source

sfReCaptchaFormPlugin

Easily add reCAPTCHA to a symfony form. This plugin is tested and built on top of sfFormExtraPlugin.

This plugin works with symfony 1.3 and 1.4.

Usage

To add recaptcha to your form, simply call embedRecaptcha() from inside the configure() method of your form:

class myForm extends BaseForm
{
  public function configure()
  {
    $this->embedRecaptcha();
  }
}

In the view, output a field called captcha as you normally would:

<?php echo $form['captcha']->render() ?>

The validation of the captcha will take place automatically.

Installation

This plugin requires the sfFormExtraPlugin plugin. Below are instructions for installing both sfReCaptchaFormPlugin and sfFormExtraPlugin.

Git

git submodule add git://github.com/weaverryan/sfReCaptchaFormPlugin.git plugins/sfReCaptchaFormPlugin
git submodule add git://github.com/diem-project/sfFormExtraPlugin.git plugins/sfFormExtraPlugin
git submodule init

SVN

svn propedit svn:externals plugins

In the resulting screen, add the following line:

sfReCaptchaFormPlugin https://svn.github.com/weaverryan/sfReCaptchaFormPlugin.git
sfFormExtraPlugin http://svn.symfony-project.com/plugins/sfFormExtraPlugin/branches/1.3/

Project Setup:

In your config/ProjectConfiguration.class.php file, add the following:

public function setup()
{
  // ...

  $this->enablePlugins(array('sfReCaptchaFormPlugin', 'sfFormExtraPlugin'));
}

Configuration

The only configuration values needed are the reCAPTCHA public and private keys. First, obtain a public and private key via https://www.google.com/recaptcha/admin/create.

Next, in your application's app.yml file, add the following:

all:
  recaptcha:
    recaptcha_public_key:   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    recaptcha_private_key:  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Advanced Configuration

The app.yml file that comes packaged with the plugin shows all of the configuration options:

Most notably, you can automatically enable recaptcha on any form by specifying the form class in app.yml. If you do this, you won't need to call embedRecaptcha() from within your form:

all:
  recaptcha:
    forms:
      myProductForm:    true

Common Problems

If you receive the error "Call to undefined method testForm::embedRecaptcha.", then either:

  • The plugin is not installed or enabled.

  • Your form extends only sfForm. It must extend sfFormSymfony. If your form is a Doctrine or Propel form, or your form extends BaseForm, then this is not the problem.

If you receive the error "You must specify the recaptcha public and private key in your sympal configuratio", then you need to specify your reCAPTCHA configuration in app.yml. See the Configuration section above.

The Fine Details

This plugin was taken from sympal CMF and was developed by both Jon Wage and Ryan Weaver.

A bug tracker is available for this plugin at http://redmine.sympalphp.org/projects/recaptchaplugin.

If you have questions, comments or anything else, email me at ryan [at] thatsquality.com