Hi, i am implementing captcha in my signup page.
The problem is it is displaying same image after page refreshes.
Here is my code.
Model.php
class Users extends CActiveRecord
{
public $verifyCode;
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
// verifyCode needs to be entered correctly
array('verifyCode','captcha','allowEmpty'=>!CCaptcha::checkRequirements(),'on'=>'create'),
);
}
Controller.php
class UsersController extends karmora
{
public function accessRules()
{
return array(
array('allow',
'actions'=>array('create', 'captcha'),
'users'=>array('*'),
),
);
}
public function actions()
{
return array(
// captcha action renders the CAPTCHA image displayed on the contact page
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xFFFFFF,
),
);
}
View.php
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'users-signup-form',
'enableAjaxValidation'=>false,
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
)); ?>
<?php if(CCaptcha::checkRequirements()): ?>
<div class="row">
<?php echo $form->labelEx($model,'verifyCode'); ?>
<div>
<?php $this->widget('CCaptcha'); ?>
<?php echo $form->textField($model,'verifyCode'); ?>
</div>
<div class="hint">Please enter the letters as shown.
<br/>Letters are not case-sensitive.
</div>
<?php echo $form->error($model,'verifyCode'); ?>
</div>
<?php endif; ?>
<?php $this->endWidget(); ?>
please guide me what is wrong with this code. it works fine if i get new code by clicking "Get new code" link.