From c4ec5e74f3836d130005129599513d8719b03bb8 Mon Sep 17 00:00:00 2001 From: ahmadinzero Date: Sat, 4 Mar 2023 10:14:20 +0700 Subject: [PATCH] fix: fixes in retrieving error messages after redirect --- system/HTTP/RedirectResponse.php | 2 +- system/Validation/Validation.php | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) 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 ?? []; } /**