/** * Check is form data is valid * * @param boolean $new * @return boolean */ public function isValid($new = true) { if ($this->fields === null) { $this->completeFields(); } $post = $this->getDataFromRequest(); if (is_array($post)) { $error = $this->checkInputData($post, $new); foreach ($post as $key => &$value) { if (!$error->has($key)) { $func = 'validate'; foreach (explode('_', $key) as $item) { $func .= Str::ucwords(Str::toLower($item)); } if (method_exists($this, $func)) { $return = $this->{$func}($value); if (Str::length($return) > 0) { $error->add($key, $return); } } } } unset($value); if (!$error->has()) { if ($this->onValidate()) { $this->data = $post; return true; } } $this->error = $error; foreach ($error->toArray() as $key => $message) { $this->fields->get($key)->error[] = $message; } } else { $this->error = new MessageBag(); foreach ($this->default as $key => $value) { if ($this->fields->has($key)) { $this->fields->get($key)->setValue($value); } } } return false; }