ソースを参照

Added form example with POST

Lukas Angerer 4 年 前
コミット
430ac30316
2 ファイル変更34 行追加0 行削除
  1. 33 0
      src/pages/form.php
  2. 1 0
      src/templates/navigation.php

+ 33 - 0
src/pages/form.php

@@ -0,0 +1,33 @@
+<?php
+    // Here we can set the <title> of the page. Since we actually render the "main content" (i.e. this file here)
+    // before we execute the wrapper HTML template (src/templates/html.php), we can define the value here and it
+    // can be used in the wrapper code.
+    $context->title = "Page With Form";
+?>
+<!-- Wome actual HTML content -->
+<h1>Please enter some stuff</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.
+-->
+<?= $context->template("navigation") ?>
+
+<form action="/form" method="POST">
+  <label for="fname">First name:</label><br>
+  <input type="text" id="fname" name="fname" value="John"><br>
+  <label for="lname">Last name:</label><br>
+  <input type="text" id="lname" name="lname" value="Doe"><br><br>
+  <input type="submit" value="Submit">
+</form> 
+
+<p>If you click the "Submit" button, the form-data will be posted back to this same page.</p>
+
+<?php
+    if ($_POST)
+    {
+        print "<p>You just POST-ed data to this page</p>";
+        print "<pre>";
+        var_dump($_POST);
+        print "</pre>";
+    }
+?>

+ 1 - 0
src/templates/navigation.php

@@ -2,4 +2,5 @@
     <li><a href="/">Home</a></li>
     <li><a href="/welcome">Welcome</a></li>
     <li><a href="/welcome/details">Details (Welcome)</a></li>
+    <li><a href="/form">Form</a></li>
 </ul>