This commit is contained in:
2025-07-03 11:49:18 +02:00
parent 4e88e4c571
commit 742c2b0160
10 changed files with 112 additions and 59 deletions

View File

@@ -10,7 +10,7 @@ class AdminController
private $db;
private $validData = array();
private $errors = array();
private $labels = array("name" => "Name*", "preis" => "€ Preis*", "dauer" => "Dauer* (Stunden)", "rabatt" => "Rabatt", "kategorie" => "Kategorie", "beschreibung" => "Beschreibung");
private $labels = array("name" => "Name*", "preis" => "€ Preis*", "dauer" => "Dauer* (Stunden)", "rabatt" => "Rabatt", "kategorie" => "Kategorie", "stadt" => "Stadt*", "strasse" => "Straße und Nummer*", "plz" => "PLZ*" ,"beschreibung" => "Beschreibung");
public function __construct($view)
@@ -19,7 +19,7 @@ class AdminController
$this->view = $view;
}
public function showForm()
public function showAdminForm()
{
$this->view->setVars([
'labels' => $this->labels,
@@ -30,22 +30,22 @@ class AdminController
public function showConfirmation()
{
echo "<p>Erfolgreich erstellt!</p>";
}
public function validateForm(){
foreach ($this->labels as $index => $value) {
if (!isset($_POST[$index]) || empty($_POST[$index])) {
$this->errors[$index] = "Bitte " . $value . " angeben";
if (strpos($value, "*") !== false && (!isset($_POST[$index]) || empty($_POST[$index]))) {
$this->errors[$index] = "Bitte " . $value . " eingeben";
} else {
$this->validData[$index] = $_POST[$index];
}
}
if (count($this->errors) > 0) {
$this->view->setDoMethodName("showForm");
$this->showForm();
$this->view->setDoMethodName("showAdminForm");
$this->showAdminForm();
} else {
if ($this->db->writeContactData($this->validData)) {
if ($this->db->writeNewCourse($this->validData, $_SESSION["user_id"])) {
$this->view->setDoMethodName("showConfirmation");
$this->showConfirmation();
}