Explorar o código

Added mechanism to process form data and prepare page data

Lukas Angerer %!s(int64=4) %!d(string=hai) anos
pai
achega
06af15c2a6
Modificáronse 3 ficheiros con 13 adicións e 1 borrados
  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;
     public $content;
     // The currently logged in user - if the user is actually logged in
     // The currently logged in user - if the user is actually logged in
     public $user;
     public $user;
+    public $pageData;
 
 
     public function __construct($requestPath)
     public function __construct($requestPath)
     {
     {
@@ -40,6 +41,12 @@ class PageContext
     public function render()
     public function render()
     {
     {
         $context = $this;
         $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
         // 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
         // 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";
     $context->title = "Page With Form";
 ?>
 ?>
 <!-- Wome actual HTML content -->
 <!-- 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
     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.
     that we can see in src/templates/navigation.