recaptcha reCAPTCHA validator

  1. Documentation
  2. Change Log

EReCaptchaValidator is a validator which uses reCAPTCHA to validate a CAPTCHA rendered by the EReCaptcha widget.

You need to have valid public and private keys for this to work. You can get them by registering yourself at http://recaptcha.net/

Current version: 1.3

Resources

Documentation

Requirements
  • Yii 1.1 or above
Installation
  • Extract the release file under protected/extensions
Usage

In the view:

<?php echo CHtml::activeLabel($user, 'validacion'); ?>
<?php $this->widget('application.extensions.recaptcha.EReCaptcha', 
   array('model'=>$user, 'attribute'=>'validacion',
         'theme'=>'red', 'language'=>'es_ES', 
         'publicKey'=>'<your public key>')) ?>
<?php echo CHtml::error($user, 'validacion'); ?>

In the model:

<?php
class UserModel extends CFormModel
{
   public $validacion;

   public function rules()
   {
      return array(
         array('validacion', 
               'application.extensions.recaptcha.EReCaptchaValidator', 
               'privateKey'=>'<your private key>'),
      );
   }
    
   public function attributeLabels()
   {
      return array(
         'validacion'=>Yii::t('demo', 'Enter both words separated by a space: '),
      );
   }
}

imehesz has noted that for this validator to work with ActiveRecord, you'll need to do something like this:

Controller:

public function actionRegister()
{
  $form = new User();

  $form->scenario = 'registerwcaptcha';
  ...
  if($form->validate())
  {
    // and here is the actual HACKY part
    $form->scenario = NULL;

    // save user registration
    $form->save();
  }
}

Model:

public function rules()
{
  return array(
                 ...
                 array(
                     'validacion',
                     'application.extensions.recaptcha.EReCaptchaValidator',
                     'privateKey'=> ENVII_CAPTCHA_PRIVATE_KEY, 
                     'on' => 'registerwcaptcha'
                 ),
                 ...
  );
}

The view remains the same.

Change Log

20110926
  • 1.3 - Updated to support SSL. Some clean-up.
20081125
  • 1.1 - Updated to fix BC broken with new CClientScript methods.
32 0
24 followers
5 636 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Validation
Developed by: MetaYii
Created on: Nov 19, 2008
Last updated: 6 years ago

Downloads

show all

Related Extensions