The Complete Solution.
Add the following in the controller
public function actions()
{
return array( // captcha action renders the CAPTCHA image displayed on the contact page
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xFFFFFF,
),
);
}
public function accessRules()
{
return array(
array('allow', 'actions'=>array('captcha'),
'users'=>array('*'),
),
);
}
In model
a. Define the variable
public $verifyCode;
b. Add variable in access rules
public function rules()
{
return array(
array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),
);
}
In the view file
<?php if(CCaptcha::checkRequirements()): ?>
<div class="row">
<div>
<?php echo $form->labelEx($model,'verifyCode'); ?>
<?php $this->widget('CCaptcha'); ?>
<?php echo $form->textField($model,'verifyCode'); ?>
<?php echo $form->error($model,'verifyCode'); ?>
</div>
<div class="hint">Please enter the letters as they are shown in the image above.
<br/>Letters are not case-sensitive.</div>
</div>
<?php endif; ?>