From 18b2463f709d76ed8b6cbd969c9b21c6eba8cf5e Mon Sep 17 00:00:00 2001 From: filip <25711588+Filip10@users.noreply.github.com> Date: Wed, 4 Dec 2024 22:18:38 +0100 Subject: [PATCH] added server side check --- App/Controllers/PostController.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/App/Controllers/PostController.php b/App/Controllers/PostController.php index cbbe33c..65002a7 100644 --- a/App/Controllers/PostController.php +++ b/App/Controllers/PostController.php @@ -48,10 +48,20 @@ public function add(): Response { $post = new Post(); // toto je pre nový post $post->setAutor($this->app->getAuth()->getLoggedUserName()); - $post->setNazov($this->request()->getValue('nazov')); - $post->setPopis($this->request()->getValue('popis')); - $post->setDatumPublikovania($this->request()->getValue('date')); + + $nazov = $this->request()->getValue('nazov'); + $popis = $this->request()->getValue('popis'); + $date = $this->request()->getValue('date'); $urlInput = (string)($this->request()->getValue('url')); + + if (empty($nazov) || empty($popis) || empty($date) || empty($urlInput)) { + // Handle the error, e.g., return an error response or show a message + throw new Exception("Všetky polia je potrebné vyplniť!"); + } + + $post->setNazov($nazov); + $post->setPopis($popis); + $post->setDatumPublikovania($date); $post->setZdroj($urlInput); $post->save();