public function validate(array $attributes = array()) { //$errors = array(); $errors = parent::validate($attributes); if (!strlen($this->name)) { $errors['name'] = _('Name can\'t be empty'); } else { if (preg_match('/[^0-9A-Za-z_-]/', $this->name)) { $errors['name'] = _('Name must contain symbols from set: A-Z, a-z, 0-9, "-", "_"'); } } if (!strlen($this->title)) { $errors['title'] = _('Title can\'t be empty'); } if (!in_array($this->role, array('guest', 'user', 'manager', 'admin', 'superuser'))) { $errors['role'] = _('Role must be either "guest", "user", "manager", "admin" or "superuser"'); } return $errors; }
public function validate(array $attributes = array()) { $errors = parent::validate($attributes); if (!strlen($this->name)) { $errors['name'] = _('Name must not be empty'); } elseif (preg_match('/[^0-9A-Za-z_-]/', $this->name)) { $errors['name'] = _('Name must contain symbols from set: A-Z, a-z, 0-9, "-", "_"'); } if (!strlen($this->title)) { $errors['title'] = 'Title must not be empty'; } $subtopics = $this->getDescendantsId(); if ($this->subtopic && !in_array($this->subtopic, $subtopics)) { $errors['subtopic'] = _('Default subtopic must be child of this topic'); } return $errors; }