title: HTML form PHP post to self to validate or submit to new page
body: <p>Upfront apology. Today is my first day working with php and I finally figured out how to get my page to post back to itself (I'd had the page as .html, instead of .php), but now I'm having trouble figuring out how to take the data to a new page after the form has been validated.  I've been working on it for quite a while and I'm fried.  Here's a simple example:</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;style&gt;
  .error {color: #FF0000;}
  &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;?php
  // Initialize variables and set to empty strings
  $firstName=$lastName="";
  $firstNameErr=$lastNameErr="";
  
  // Validate input and sanitize
  if ($_SERVER['REQUEST_METHOD']== "POST") {
     if (empty($_POST["firstName"])) {
        $firstNameErr = "First name is required";
     }
     else {
        $firstName = test_input($_POST["firstName"]);
     }
     if (empty($_POST["lastName"])) {
        $lastNameErr = "Last name is required";
     }
     else {
        $lastName = test_input($_POST["lastName"]);
     }
  }
  
  // Sanitize data
  function test_input($data) {
     $data = trim($data);
     $data = stripslashes($data);
     $data = htmlspecialchars($data);
     return $data;
  }
  ?&gt;
  
  &lt;h2&gt;Find Customer&lt;/h2&gt;
  &lt;p&gt;&lt;span class="error"&gt;* required&lt;/span&gt;&lt;/p&gt;
  &lt;form action="&lt;?php echo htmlspecialchars($_SERVER['PHP_SELF']);?&gt;" method="post"&gt;
  First Name: &lt;input type="text" name="firstName" value="&lt;?php echo $firstName; ?&gt;"&gt;&lt;span class="error"&gt;* &lt;?php echo $firstNameErr; ?&gt;&lt;/span&gt;&lt;br&gt;&lt;br&gt;
  Last Name: &lt;input type="text" name="lastName" value="&lt;?php echo $lastName; ?&gt;"&gt;&lt;span class="error"&gt;* &lt;?php echo $lastNameErr; ?&gt;&lt;br&gt;&lt;br&gt;
  &lt;input type="submit"&gt;
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>OK. So above, you'll see that the form posts back to itself so it can validate.  Good. Now, considering all things are valid, how do I post to another script (action="otherAction.php", maybe?) so the data can actually be processed?</p>
  
  <p>Also, any security suggestions are appreciated. I did my best to take security into account. Thanks.</p>