From 8dd24a8c1eb4fb016e17af7ca4ce9a45604a4d2c Mon Sep 17 00:00:00 2001 From: pbbfa23abi Date: Mon, 23 Jun 2025 11:37:52 +0200 Subject: [PATCH 1/2] forms styling WIP --- CSS/Element/form.css | 54 ++++++++++++++++++++++++++++++++++ CSS/style.css | 50 ++----------------------------- CSS/variables.css | 4 +++ Controller/AdminController.php | 5 ++-- Views/Admin/showForm.phtml | 32 ++++++++++++-------- 5 files changed, 83 insertions(+), 62 deletions(-) create mode 100644 CSS/Element/form.css diff --git a/CSS/Element/form.css b/CSS/Element/form.css new file mode 100644 index 0000000..79cdc70 --- /dev/null +++ b/CSS/Element/form.css @@ -0,0 +1,54 @@ +.form-flex { + display: flex; + flex-direction: column; + row-gap: 8px; + align-items: center; + width: 100%; +} + +form label { + width: fit-content; +} + +form input { + border: var(--border-primary); + height: var(--h-md); + padding-left: 8px; + padding-right: 8px; +} + +.input { + display: flex; + flex-direction: column; + row-gap: 2px; + align-items: start; +} + +.input-short { + max-width: 240px; +} + +.form-grid { + display: grid; + grid-template-columns: repeat(2, 1fr); + gap: 20px; + max-width: 600px; +} + +.form-grid label { + display: flex; + flex-direction: column; + font-weight: bold; +} + +.form-grid textarea { + grid-column: span 2; + resize: vertical; + min-height: 100px; +} + +input, textarea { + padding: 8px; + font-size: 1rem; + margin-top: 5px; +} diff --git a/CSS/style.css b/CSS/style.css index 46a6f7b..b2796a7 100644 --- a/CSS/style.css +++ b/CSS/style.css @@ -2,6 +2,7 @@ @import url(Block/header.css); @import url(Block/footer.css); @import url(Element/logo.css); +@import url(Element/form.css); @import url(Element/button.css); *, *:before, *:after { @@ -11,8 +12,6 @@ font-family: var(--font-family-main); } - - body { background-color: var(--brand-background); color: #666; @@ -31,8 +30,6 @@ h1 span { font-size: 40px; } - - h2 { color: orange; } @@ -80,48 +77,6 @@ main { font-weight: bold; } -/*** Formulare ***/ - -form { - width: 440px; - margin: auto; -} - -label { - width: 120px; - display: inline-block; - margin: 5px 15px 10px 0; - vertical-align: top; - text-align: right; -} - -label.errorMsg { - width: 420px; - display: inline-block; - margin: 0 5px 15px 0; - vertical-align: top; - text-align: right; - color: orange; -} - -input { - width: 300px; -} - -input[type="submit"] { - width: 100px; - margin-left: 330px; -} - -form textarea { - width: 300px; - height: 150px; - margin-bottom: 10px; -} - -form select { - width: 300px; -} /*** Loesung Workshop-Seite ***/ .textContent { @@ -156,4 +111,5 @@ form select { .hover:hover{ opacity: .75; text-decoration: none; -} \ No newline at end of file +} + diff --git a/CSS/variables.css b/CSS/variables.css index af9c0e0..f72b739 100644 --- a/CSS/variables.css +++ b/CSS/variables.css @@ -2,10 +2,12 @@ /* Colors*/ --brand-primary: #EB8202; --brand-background: #201911; + --bg-muted: #5B5B5B; --brand-white: #ffffff; --fullblock: darkblue; --input-placeholder: #998E82; + /*Fonts*/ --font-family-main: "Inter", sans-serif; --font-family-headline: "Source Serif 4", serif; @@ -19,4 +21,6 @@ /*Font-Weight*/ --font-weight-semibold: 600; + --h-md: 48px; + --border-primary: 1px solid #998E82; } \ No newline at end of file diff --git a/Controller/AdminController.php b/Controller/AdminController.php index 81ee77f..8daa158 100644 --- a/Controller/AdminController.php +++ b/Controller/AdminController.php @@ -41,10 +41,9 @@ class AdminController $this->validData[$index] = $_POST[$index]; } } - if (count($this->errors) > 0) { - $this->view->setDoMethodName("showContactForm"); - $this->showContactForm(); + $this->view->setDoMethodName("showForm"); + $this->showForm(); } else { if ($this->db->writeContactData($this->validData)) { $this->view->setDoMethodName("showConfirmation"); diff --git a/Views/Admin/showForm.phtml b/Views/Admin/showForm.phtml index bb2234a..92f0079 100644 --- a/Views/Admin/showForm.phtml +++ b/Views/Admin/showForm.phtml @@ -5,26 +5,34 @@ include dirname(__DIR__).'/header.phtml';

Neuer Kurs

-
+ - $value) { - echo ''; - if ($index == "beschreibung") { - echo "
"; } else { - echo '
'; + echo '
'; } - if (isset($errors[$index])) { - echo '
'; + if (isset($errors[$key])) { + echo '
'; } + echo ''; + $index++; } - ?> - - + +
\ No newline at end of file From c483058b1bf511d959f8df6fb908db3bdaa83aa1 Mon Sep 17 00:00:00 2001 From: pbbfa23abi Date: Mon, 23 Jun 2025 12:18:22 +0200 Subject: [PATCH 2/2] Form util classes + write Kurs Methode --- CSS/Element/form.css | 11 +++++++++-- CSS/style.css | 3 +-- Controller/AdminController.php | 4 ++-- Model/AdminModel.php | 25 ++++++++++++++++++++++++- Views/Admin/showForm.phtml | 4 ---- Views/Contact/showContactForm.phtml | 3 ++- 6 files changed, 38 insertions(+), 12 deletions(-) diff --git a/CSS/Element/form.css b/CSS/Element/form.css index 79cdc70..29410dc 100644 --- a/CSS/Element/form.css +++ b/CSS/Element/form.css @@ -22,6 +22,7 @@ form input { flex-direction: column; row-gap: 2px; align-items: start; + width: 100%; } .input-short { @@ -32,7 +33,9 @@ form input { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; + width: 100%; max-width: 600px; + margin: auto; } .form-grid label { @@ -42,9 +45,13 @@ form input { } .form-grid textarea { - grid-column: span 2; - resize: vertical; min-height: 100px; + width: 100%; +} + +.form-grid input:last-child, div:nth-last-child(4) { + grid-column: 1 / -1; + column-span: 2; } input, textarea { diff --git a/CSS/style.css b/CSS/style.css index b2796a7..ae458ab 100644 --- a/CSS/style.css +++ b/CSS/style.css @@ -41,8 +41,7 @@ main { #wrapper { max-width: 90%; - margin: 0 auto; - color: white; + margin: 0 auto } .msg { diff --git a/Controller/AdminController.php b/Controller/AdminController.php index 8daa158..a8e81ae 100644 --- a/Controller/AdminController.php +++ b/Controller/AdminController.php @@ -10,7 +10,7 @@ class AdminController private $db; private $validData = array(); private $errors = array(); - private $labels = array("name" => "Name*", "preis" => "Preis*", "dauer" => "Dauer*", "rabatt" => "Rabatt", "kategorie" => "Kategorie", "beschreibung" => "Beschreibung"); + private $labels = array("name" => "Name*", "preis" => "€ Preis*", "dauer" => "Dauer* (Stunden)", "rabatt" => "Rabatt", "kategorie" => "Kategorie", "beschreibung" => "Beschreibung"); public function __construct($view) @@ -30,7 +30,7 @@ class AdminController public function showConfirmation() { - + echo "

Erfolgreich erstellt!

"; } public function validateForm(){ diff --git a/Model/AdminModel.php b/Model/AdminModel.php index 402913d..6177b99 100644 --- a/Model/AdminModel.php +++ b/Model/AdminModel.php @@ -6,7 +6,30 @@ use PDOException; class AdminModel extends Database { - public function writeContactData($values) + public function writeNewCourse($values) { + $guid = $this->createUUID(); + + $sql = "INSERT INTO kurs (`id`, `name`, `preis`, `dauer`, `rabatt`, `kategorie`, `beschreibung`) VALUES ( + :guid, :name, :preis, :dauer, :rabatt, :kategorie, :beschreibung);"; + + $pdo = $this->linkDB(); + + try { + $sth = $pdo->prepare($sql); + $sth->execute(array(":guid" => $guid, + ":name" => $values["name"], + ":preis" => $values["preis"], + ":dauer" => $values["dauer"], + ":rabatt" => $values["rabatt"], + ":kategorie" => $values["kategorie"], + ":beschreibung" => $values["beschreibung"], + )); + } catch (PDOException $e) { + new \Blog\Library\ErrorMsg("Fehler beim Schreiben der Daten.", $e); + die; + } + + return true; } } \ No newline at end of file diff --git a/Views/Admin/showForm.phtml b/Views/Admin/showForm.phtml index 92f0079..2b7b1db 100644 --- a/Views/Admin/showForm.phtml +++ b/Views/Admin/showForm.phtml @@ -11,12 +11,8 @@ include dirname(__DIR__).'/header.phtml'; $index = 0; foreach ($labels as $key => $value) { - if ($key == "beschreibung") { - if($index % 2 != 0) echo '
'; - } echo '
'; if ($key == "beschreibung") { - if($index % 2 != 0) echo '
'; echo "
"; diff --git a/Views/Contact/showContactForm.phtml b/Views/Contact/showContactForm.phtml index 434a72f..cd61566 100644 --- a/Views/Contact/showContactForm.phtml +++ b/Views/Contact/showContactForm.phtml @@ -31,6 +31,7 @@ include dirname(__DIR__).'/header.phtml'; - + + \ No newline at end of file