Yii Framework Forum: Yiistrap Captcha - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yiistrap Captcha Use captcha together with yiistrap Rate Topic: ***** 3 Votes

#1 User is offline   speculatius 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 13-December 11

Posted 17 August 2013 - 08:58 AM

Hi,

there is no direct support for captcha in the new Yiistrap. I would like to share my simple solution for this.

Controller

Define CCaptchaAction as usually:

public function actions() {
  return array(
    // ...
    'captcha' => array(
      'class' => 'CCaptchaAction',
      'backColor' => 0xFFFFFF,
    ),
    // ...
  );
}


Model

Use captcha validator as usually:

public function rules() {
  return array(
    // ...
    array('verifyCode', 'captcha', 'allowEmpty' => ! CCaptcha::checkRequirements()),
    // ...
  );
}


View

Here comes the trick:

<?php echo $form->textFieldControlGroup($model, 'verifyCode', array(
  'help' => 'Please enter the letters as they are shown in the image above.',
  'controlOptions' => array('before' => $this->widget('system.web.widgets.captcha.CCaptcha', array(), true) . '<br/>'),
)); ?>

3

#2 User is offline   mattbflo 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 27-September 13

Posted 27 September 2013 - 01:44 PM

Thank you very much for posting this! Works great.
0

#3 Guest_Interboy_*

  • Group: Guests

Posted 22 October 2013 - 10:37 PM

We can see Capcha Action in Yii Blog demo.
Anyway, thanks for your effort
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users