diff --git a/Controller/AdminController.php b/Controller/AdminController.php new file mode 100644 index 0000000..81ee77f --- /dev/null +++ b/Controller/AdminController.php @@ -0,0 +1,56 @@ + "Name*", "preis" => "Preis*", "dauer" => "Dauer*", "rabatt" => "Rabatt", "kategorie" => "Kategorie", "beschreibung" => "Beschreibung"); + + + public function __construct($view) + { + $this->db = new AdminModel(); + $this->view = $view; + } + + public function showForm() + { + $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(); + } + } + } +} +?> \ No newline at end of file diff --git a/Model/AdminModel.php b/Model/AdminModel.php new file mode 100644 index 0000000..402913d --- /dev/null +++ b/Model/AdminModel.php @@ -0,0 +1,12 @@ + + + + +

Neuer Kurs

+
+ + $value) { + echo ''; + if ($index == "beschreibung") { + echo "
"; + } else { + echo '
'; + } + if (isset($errors[$index])) { + echo '
'; + } +} + +?> + + + +
+ + \ No newline at end of file