Hi , i am using captcha in my Signup form. The problem is, it is not showing any image. it just show this text.
"Get a new code"
Clicking on the text gives me error
"Unable to resolve the request "captcha/refresh/1"
On page load it also generates error
"NetworkError: 404 Not Found - http://localhost/myapp/captcha/v/5253d1a155702"
i have checked, jquery is also loaded.
Here is my code for captcha.
Model: Users.php
class Users extends CActiveRecord
{
public $verifyCode;
public function rules(){
return array(
array('verifyCode','captcha','allowEmpty'=>!CCaptcha::checkRequirements()),
);
}
Controller: UsersController
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 user registration page
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xFFFFFF,
),
);
}
View: Signup.php
<?php
//clearing captcha session values to get updated captcha image
$session = Yii::app()->session;
$prefixLen = strlen(CCaptchaAction::SESSION_VAR_PREFIX);
foreach ($session->keys as $key) {
if (strncmp(CCaptchaAction::SESSION_VAR_PREFIX, $key, $prefixLen) == 0)
$session->remove($key);
}
if(CCaptcha::checkRequirements()):
echo $form->labelEx($model,'verifyCode', array('class' => 'fieldname'));
echo $form->textField($model,'verifyCode'); ?>
<span class="captcha">
<?php $unique_id = rand(0,9999); ?>
<?php $this->widget('CCaptcha', array('buttonOptions' => array('id' => $unique_id),'id'=>'image_captcha')); ?>
<?php echo $form->error($model,'verifyCode'); ?>
</span>
<?php endif; ?>
I am unable to understand why it is not wroking. please help me.