mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-17 14:57:23 +08:00
refacotring validators.
This commit is contained in:
@@ -30,6 +30,17 @@ class CaptchaValidator extends Validator
|
||||
public $captchaAction = 'site/captcha';
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the validator.
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
if ($this->message === null) {
|
||||
$this->message = Yii::t('yii|The verification code is incorrect.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the attribute of the object.
|
||||
* If there is any error, the error message is added to the object.
|
||||
@@ -40,8 +51,7 @@ class CaptchaValidator extends Validator
|
||||
{
|
||||
$value = $object->$attribute;
|
||||
if (!$this->validateValue($value)) {
|
||||
$message = $this->message !== null ? $this->message : Yii::t('yii|The verification code is incorrect.');
|
||||
$this->addError($object, $attribute, $message);
|
||||
$this->addError($object, $attribute, $this->message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,8 +93,7 @@ class CaptchaValidator extends Validator
|
||||
public function clientValidateAttribute($object, $attribute)
|
||||
{
|
||||
$captcha = $this->getCaptchaAction();
|
||||
$message = $this->message !== null ? $this->message : \Yii::t('yii|The verification code is incorrect.');
|
||||
$message = strtr($message, array(
|
||||
$message = strtr($this->message, array(
|
||||
'{attribute}' => $object->getAttributeLabel($attribute),
|
||||
'{value}' => $object->$attribute,
|
||||
));
|
||||
@@ -102,7 +111,7 @@ if(h != hash) {
|
||||
}
|
||||
";
|
||||
|
||||
if ($this->allowEmpty) {
|
||||
if ($this->skipOnEmpty) {
|
||||
$js = "
|
||||
if($.trim(value)!='') {
|
||||
$js
|
||||
|
||||
Reference in New Issue
Block a user