public function validate() { $this->error_if_empty("username"); if ($this->user->is_new_record()) { $this->error_if_empty("password"); } if (User::count_admins() < 2 && $this->user->admin && !$this->params["admin"]) { $this->add_error("admin", "Can't remove last admin."); } }