Hi I'm trying to do my best at Yii captcha implementation but I am stuck. There are weird stuff.
1. Even if i write it correctly the message errors shows up. I have to press the "Get a new code" and after that it will work. See the image:
2. This message errors is generate by on key event for some reason I guess. I want to generate the message error only when I press a submit button, which do a ajax request.
This is my model:
public $verifyCode;
....
public function rules() {
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
if ($this->scenario == "insert") {
return array(
array('requisition_id, sync', 'numerical', 'integerOnly' => true),
array('lastname, firstname, email, dob, phone, cv_path, experienceMonths, experienceYears, competencies, token', 'required', 'message' => "Câmpul este obligatoriu"),
array('email', 'email', 'message' => "Emailul este invalid!"),
array('dob', 'validateDob'),
array('dayOfBirth, monthOfBirth, yearOfBirth', 'safe'),
array('taleo_id, sync', 'required', 'on' => 'taleoUpdate'),
array('verifyCode', 'captcha', 'captchaAction'=>'site/captcha')
// The following rule is used by search().
// Please remove those attributes that should not be searched.
);
} else if ($this->scenario == 'taleoUpdate') {
return array(
array('taleo_id, sync', 'required'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
);
}
else if($this->scenario == 'notjobapply'){
return array(
array('lastname, firstname, email, phone, cv_path, requisition_id', 'required', 'message'=>'Câmpul este obligatoriu'),
array('email', 'email', 'message' => "Emailul este invalid!"),
);
}
}
and this is the controller
public function accessRules()
{
return array(
array('allow',
'actions'=>array('aplica', 'captcha'),
'users'=>array('*'),
),
);
}
....
$this->render('apply', array(
"applicant" => $model,
'job' => $job,
'region' => $region,
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xFFFFFF,
),
));
and finally the view:
<?php
if(CCaptcha::checkRequirements()){ ?>
<?php echo $form->labelEx($applicant,'verifyCode'); ?><br>
<?php $this->widget('CCaptcha', array('captchaAction'=>'site/captcha')); ?> <br><br>
<?php echo $form->textField($applicant,'verifyCode'); ?><br>
<?php echo $form->error($applicant,'verifyCode'); ?><br><br>
<?php } ?>
For the user model validation rules i use these:
public function rules()
{
return array(
array('isActive, parentId, role, ban, isLegalEntity, organization, discount, paymentDelay, debtLimit, PaymentMethod, ShippingMethod, KnowingSource, scopeOfActivity, ShablonId, agree, Group', 'numerical', 'integerOnly'=>true),
array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements(),'on' => 'register'),
...
),
},
What if you try the same: array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements(),'on' => 'register')
?
Also make sure in your controller you've defined the captcha action like these:
class UserController extends Controller
{
public function actions()
{
return array(
// captcha action renders the CAPTCHA image displayed on the contact page
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xFF2F2F,
),
);
}
....
}