diff --git a/system/HTTP/RedirectResponse.php b/system/HTTP/RedirectResponse.php index ed620c40f2ae..28b1d13b75eb 100644 --- a/system/HTTP/RedirectResponse.php +++ b/system/HTTP/RedirectResponse.php @@ -114,7 +114,7 @@ private function withErrors(): self if ($validation->getErrors()) { $session = Services::session(); - $session->setFlashdata('_ci_validation_errors', $validation->getErrors()); + $session->setFlashdata('_ci_validation_errors', serialize($validation->getErrors())); } return $this; diff --git a/system/Validation/Validation.php b/system/Validation/Validation.php index c22f38ae2413..a75033a900d8 100644 --- a/system/Validation/Validation.php +++ b/system/Validation/Validation.php @@ -729,7 +729,11 @@ public function getError(?string $field = null): string */ public function getErrors(): array { - return $this->errors; + if (empty($this->errors) && ! is_cli() && isset($_SESSION, $_SESSION['_ci_validation_errors'])) { + $this->errors = unserialize($_SESSION['_ci_validation_errors']); + } + + return $this->errors ?? []; } /**