protected function validateAttribute($object, $attribute) { $value = $object->{$attribute}; if (!$this->isCharsetCorrect($value)) { $message = $this->wrongCharset !== null ? $this->wrongCharset : Yii::t('yii', 'Wrong character set.'); $object->{$attribute} = ''; $this->addError($object, $attribute, $message); } parent::validateAttribute($object, $attribute); }
/** * Validates the given string and checks if it contains LLD macros. */ public function validate($value) { if (!parent::validate($value)) { return false; } // check if a string contains an LLD macro if (!zbx_empty($value) && !preg_match('/(\\{#' . ZBX_PREG_MACRO_NAME_LLD . '\\})+/', $value)) { $this->error($this->messageMacro); return false; } return true; }
public function __construct(array $options = array()) { $this->messageRegex = _('Colour "%1$s" is not correct: expecting hexadecimal colour code (6 symbols).'); $this->messageEmpty = _('Empty color.'); parent::__construct($options); }
/** * Checks config * This is the 'checkConfig' validator as declared in rules(). */ public function checkConfig($attribute, $params) { //if owner_name class exists in configuration if (count($this->config) === 0) { if ($attribute === 'owner_name') { $this->addError($attribute, Yii::t('CommentsModule.msg', 'This item cann\'t be commentable')); } return; } //if only registered users can post comments if ($attribute === 'creator_id' && ($this->config['registeredOnly'] === true || Yii::app()->user->isGuest === false)) { unset($this->user_email, $this->user_name); $numberValidator = new CNumberValidator(); $numberValidator->allowEmpty = false; $numberValidator->integerOnly = true; $numberValidator->attributes = array('creator_id'); $numberValidator->validate($this); } //if se captcha validation on posting if ($attribute === 'verifyCode' && $this->config['useCaptcha'] === true) { $captchaValidator = new CCaptchaValidator(); $captchaValidator->caseSensitive = false; $captchaValidator->captchaAction = Yii::app()->urlManager->createUrl(CommentsModule::CAPTCHA_ACTION_ROUTE); $captchaValidator->allowEmpty = !CCaptcha::checkRequirements(); $captchaValidator->attributes = array('verifyCode'); $captchaValidator->validate($this); } //if not only registered users can post comments and current user is guest if (($attribute === 'user_name' || $attribute === 'user_email') && ($this->config['registeredOnly'] === false && Yii::app()->user->isGuest === true)) { unset($this->creator_id); $requiredValidator = new CRequiredValidator(); $requiredValidator->attributes = array($attribute); $requiredValidator->validate($this); $stringValidator = new CStringValidator(); $stringValidator->max = 128; $stringValidator->attributes = array($attribute); $stringValidator->validate($this); if ($attribute === 'user_email') { $emailValidator = new CEmailValidator(); $emailValidator->attributes = array('user_email'); $emailValidator->validate($this); } } }