User Tools

Site Tools


basic_form

Getting Started Part 5: Basic HTML Form

Creating a basic HTML form

Create a new file on your server called form.php and enter this code. Visit it in your browser and see the result.

<form method='post' action=''>
<input type='text' name='search_keyword'>
<input type='submit' name='search_button' value='Search'>
</form>

Adding some PHP code to dump the form conents

<?php
echo "<pre>";
print_r($_REQUEST);
echo "</pre>";
?>

Full working example

<html>
  <form method='post' action=''>
    <input type='text' name='forename'>
    <input type='submit' name='say_hello' value='Say hello'>
  </form>

  <?php
   if(!empty($_REQUEST['forename'])) {
     echo "Hello {$_REQUEST['forename']}";
   }
  ?>
</html>

Error reporting

Add this to the very top of your file to enable error reporting and see how that changes the output of your form.php file.

<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
?>

Note: We'll start with this, then explain how to make it not as full-of-errors :)

basic_form.txt · Last modified: 2019/09/10 12:06 by nmckillop