Creating a form

We will need a form with which to test this script with. Lets create an HTML page with one now.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> 
  <head> 
    <meta http-equiv="Content-type" content="text/html; charset=utf-8"> 
    <title>Contactn Form</title> 
  </head> 
  <body> 
    <h1>Contact Form</h1> 
    <p>
      Please fill in all the fields below or the form will not be processed
    </p> 
    <form action="formProcessor.php" method="post" accept-charset="utf-8"> 
      <p> 
        <label for="name">Name:</label> 
        <input type="text" name="name" value="" /> 
      </p> 
      <p> 
        <label for="email">Email:</label> 
        <input type="text" name="email" value="" /> 
      </p> 
      <p> 
        <label for="phone">Phone:</label> 
        <input type="text" name="phone" value="" /> 
      </p> 
      <p> 
        <label for="message">Message:</label> 
        <textarea name="message" rows="4" cols="40"></textarea> 
      </p> 
      <p>
        <input type="submit" value="Submit">
      </p> 
    </form> 
  </body> 
</html>

As you can see we have a simple HTML document that contains a header, a message to the user and a form, all with absolutely no style. Our form has 3 text inputs, a textarea and a submit button, all with labels to let the user know what goes where.

Notice that the action of the form is "formProcessor.php". Obviously we will need to create this file, in the same directory as our form. If you are using a different directory structure, be sure to adjust the relative path as necessary.

Now Lets take a look at that form processor script.