Код: Выделить всё
public function rules()
{
return array(
array('verifyCode','captcha','allowEmpty'=>!extension_loaded('gd'))
);
}
Код: Выделить всё
/**
* Validates the input to see if it matches the generated code.
* @param string user input
* @param boolean whether the comparison should be case-sensitive
* @return whether the input is valid
*/
public function validate($input,$caseSensitive)
{
$code=$this->getVerifyCode();
$valid=$caseSensitive?($input===$code):!strcasecmp($input,$code);
// Следующей строчки кода и не хватает
// Эта строчка проверяет что запрос на проверку - аякс, и не нужно перегенерировать капчу.
if(Yii::app()->request->isAjaxRequest) return $valid;
$session=Yii::app()->session;
$session->open();
$name=$this->getSessionKey().'count';
$session[$name]=$session[$name]+1;
if($session[$name]>$this->testLimit && $this->testLimit>0)
$this->getVerifyCode(true);
return $valid;
}