21.12. How to display HTML forms in a module

When you have HTML forms in a module, you may run into problems with passing the values from the form fields to the module itself. Here is just a simple form that you can use as a starting point for your own module with forms - just make a folder named Testing (for instance) in your modules folder, and put an index.php in it with the following code (see File doesn't exist error when posting with a form):

<?php
if (!eregi("modules.php", $PHP_SELF)) {
  die ("You can't access this file directly...");
}
require_once("mainfile.php");
include("header.php");
$module_name = basename(dirname(__FILE__));
echo "<center><form action=\"modules.php?name=$module_name\" method=\"post\"> "
."Name: <input type=\"text\" name=\"yourname\" size=\"20\" 
  value=\"$yourname\">&nbsp;&nbsp;"
."<input type=\"hidden\" name=\"test_input\" value=\"test is good\">"
."<input type=\"submit\" value=\"Submit\"></form></center>";
if($test_input != "") {
  echo "<br>Form worked, and yourname is $yourname";
}
include("footer.php");
?>