Procházet zdrojové kódy

Added mechanism to process form data and prepare page data

Lukas Angerer před 4 roky
rodič
revize
06af15c2a6
3 změnil soubory, kde provedl 13 přidání a 1 odebrání
  1. 7 0
      src/lib/PageContext.php
  2. 5 0
      src/pages/form-post.php
  3. 1 1
      src/pages/form.php

+ 7 - 0
src/lib/PageContext.php

@@ -12,6 +12,7 @@ class PageContext
     public $content;
     // The currently logged in user - if the user is actually logged in
     public $user;
+    public $pageData;
 
     public function __construct($requestPath)
     {
@@ -40,6 +41,12 @@ class PageContext
     public function render()
     {
         $context = $this;
+        $postHandler = substr($this->targetPage, 0, -4) . "-post.php";
+
+        if ($_SERVER['REQUEST_METHOD'] === 'POST' && is_file($postHandler))
+        {
+            $this->pageData = include $postHandler;
+        }
 
         // Start output buffering - everything that is "printed" while we are buffering
         // is captured for later use which allows us to insert the content into a larger

+ 5 - 0
src/pages/form-post.php

@@ -0,0 +1,5 @@
+<?php
+
+return array(
+    "title" => "POSTed FORM",
+);

+ 1 - 1
src/pages/form.php

@@ -5,7 +5,7 @@
     $context->title = "Page With Form";
 ?>
 <!-- Wome actual HTML content -->
-<h1>Please enter some stuff</h1>
+<h1><?= empty($context->pageData["title"]) ? "Please enter some stuff" : $context->pageData["title"] ?></h1>
 <!--
     We can also use other, smaller "templates" to build up our page. Here, we just load the navigation snippet
     that we can see in src/templates/navigation.