/** The procedure for the validation attributes before post changes */ public function validate() { if ($this->_scenario == self::SC_INSERT) { if ($this->_uploadedFile->hasError()) { $this->addError('fileid', _('Upload error, try again later.')); } if ($this->getSizeMb() > (double) App::getAppC()['maxUploadMb']) { $this->addError('fileid', sprintf(_('The max file at Mb for upload is %s MB'), App::getAppC()['maxUploadMb'])); } } }
public function validate() { if ($this->_scenario == self::SC_INSERT) { /** * @param Model $model * @param string $attr * @return string */ function invalidText($model, $attr) { return _('Invalid filed') . ' ' . _($model->getAttributeCaption($attr)); } foreach (array('loginname', 'email') as $attr) { if ($this::model()->findByAttributes(array($attr => $this->{$attr}), array())) { $this->addError($attr, invalidText($this, $attr) . ' ' . _('Already exists')); } } if (!preg_match('/^[a-z0-9_-]{3,15}$/', $this->loginname)) { $this->addError('loginname', invalidText($this, 'loginname') . ' ' . sprintf(_('A maximum of %s at least %s characters.'), '3', '15')); } if (!filter_var($this->email, FILTER_VALIDATE_EMAIL)) { $this->addError('email', invalidText($this, 'email')); } if (!preg_match('/[0-9A-Za-z!@#$%*]{8,}/', $this->password)) { $this->addError('password', invalidText($this, 'password') . ' ' . sprintf(_('A minimum of %s characters letters and numbers'), '8')); } if ($this->password != $this->passwordConfirm) { $this->addError('passwordConfirm', _("Passwords don't match")); } if (App::isAjaxRequest()) { return; } $this->image = new UploadedFile('image', $this); if ($this->image->hasError()) { switch ($this->image->getError()) { case UPLOAD_ERR_NO_FILE: $this->addError('image', _('Image is required')); break; default: $this->addError('image', invalidText($this, 'image')); break; } } } else { if ($this->_scenario == self::SC_UPDATE) { } } }