Giter Club home page Giter Club logo

sfrecaptchaformplugin's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.