WIP
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user