From 582db52aa6ecd182ce540f68c80622f8fb5d2637 Mon Sep 17 00:00:00 2001 From: Illia Hromovoi Date: Thu, 3 Jul 2025 11:52:12 +0200 Subject: [PATCH] =?UTF-8?q?validation=20f=C3=BCr=20registration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controller/UserController.php | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/Controller/UserController.php b/Controller/UserController.php index b9e1104..d4b2d5d 100644 --- a/Controller/UserController.php +++ b/Controller/UserController.php @@ -31,11 +31,19 @@ class UserController{ } public function showUserRegisterForm(){ + if (!isset($this->errors)) { + $this->errors = []; + } + if (!isset($this->validData)) { + $this->validData = []; + } + $this->view->setVars([ - 'labels' => $this->labels, - 'errors' => $this->errors, - 'validData' => $this->validData - ]); + 'labels' => $this->labels, + 'errors' => $this->errors, + 'validData' => $this->validData + ]); + } public function showUserRegisterConfirmation(){ @@ -98,8 +106,15 @@ class UserController{ } public function register(){ - $this->db->createUser($_POST); - $this->login(); + $this->validateForm(); + + if(count($this->errors) > 0){ + $this->view->setDoMethodName("showUserRegisterForm"); + $this->showUserRegisterForm(); + } else{ + $this->db->createUser($_POST); + $this->login(); + } } public function login(){