From 4fa775f3265e8cf54bc9c02bfaf94ac0a87273f4 Mon Sep 17 00:00:00 2001 From: Max538 Date: Mon, 16 Jun 2025 15:12:13 +0200 Subject: [PATCH] implemented authcontroller logic --- Controller/AuthController.php | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Controller/AuthController.php diff --git a/Controller/AuthController.php b/Controller/AuthController.php new file mode 100644 index 0000000..646442c --- /dev/null +++ b/Controller/AuthController.php @@ -0,0 +1,55 @@ + "Name", "email" => "E-Mail-Adresse", "content" => "Nachricht"); + + + public function __construct($view) + { + $this->db = new AuthModel(); + $this->view = $view; + } + + public function showAuthForm() + { + $this->view->setVars([ + 'labels' => $this->labels, + 'validData' => $this->validData, + 'errors' => $this->errors + ]); + } + + public function showConfirmation() + { + + } + + public function validateForm(){ + foreach ($this->labels as $index => $value) { + if (!isset($_POST[$index]) || empty($_POST[$index])) { + $this->errors[$index] = "Bitte " . $value . " angeben"; + } else { + $this->validData[$index] = $_POST[$index]; + } + } + + if (count($this->errors) > 0) { + $this->view->setDoMethodName("showContactForm"); + $this->showContactForm(); + } else { + if ($this->db->writeContactData($this->validData)) { + $this->view->setDoMethodName("showConfirmation"); + $this->showConfirmation(); + } + } + } +}