title: Prevent redirection on form submission
body: <p>I have recently (with a little bit of help) written this simple form to email script. It works, the only problem is that it redirects to the included php script when run. Does anybody have any ideas on how to stop this from happening and instead just showing a thank you note on the original page?</p>
  
  <p>index.php</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;Megaform&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
    &lt;?php include 'form.php' ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>form.php</p>
  
  <pre><code>&lt;form name="email" method="post" action="email.php"&gt;
    &lt;p&gt;
      &lt;label for="name"&gt;Full Name&lt;/label&gt;
      &lt;input type="text" name="name" id="name"&gt;
    &lt;/p&gt;
    &lt;p&gt;
      &lt;label for="email"&gt;Email Address&lt;/label&gt;
      &lt;input type="text" name="email" id="email"&gt;
    &lt;/p&gt;
    &lt;p&gt;
      &lt;label for="phone"&gt;Phone Number&lt;/label&gt;
      &lt;input type="text" name="phone" id="phone"&gt;
    &lt;/p&gt;
    &lt;p&gt;
      &lt;label for="subject"&gt;Subject&lt;/label&gt;
      &lt;input type="text" name="subject" id="subject"&gt;
    &lt;/p&gt;
    &lt;p&gt;
      &lt;label for="message"&gt;Message&lt;br&gt;
      &lt;/label&gt;
      &lt;textarea name="message" id="message" cols="45" rows="5"&gt;&lt;/textarea&gt;
    &lt;/p&gt;
    &lt;p&gt;&lt;input type="submit" name="send" id="send" value="Submit"&gt;&lt;input type="reset" name="send" id="send" value="Reset"&gt;
    &lt;/p&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>email.php</p>
  
  <pre><code>&lt;?php  
  
  // Get the Variables
    $name = $_POST['name'];
    $visitor_email = $_POST['email'];
    $phone = $_POST['phone'];
    $subject = $_POST['subject'];
    $message = $_POST['message'];
  
  
  // Validate against spammers
  function IsInjected($str)
  {
      $injections = array('(\n+)',
             '(\r+)',
             '(\t+)',
             '(%0A+)',
             '(%0D+)',
             '(%08+)',
             '(%09+)'
             );
  
      $inject = join('|', $injections);
      $inject = "/$inject/i";
  
      if(preg_match($inject,$str))
      {
        return true;
      }
      else
      {
        return false;
      }
  }
  
  if(IsInjected($visitor_email))
  {
      echo "Bad email value!";
      exit;
  }
  
  
  // Compose the Email
      $email_from = 'a@b.com';  // Set a valid email address that the form can use
  
      $email_subject = "New Form submission - $subject";  //  Change the message subject here
  
      $email_body = "You have received a new message from $name ($phone) .\n Here is the message:\n $message";
  
  
  // Send The Email
    $to = "c@d.com";  // Set a valid email address to send the form to
  
    $headers = "From: $email_from \r\n";
  
    $headers .= "Reply-To: $visitor_email \r\n";
  
    mail($to,$email_subject,$email_body,$headers);
  
  ?&gt;
  &lt;p&gt;Thankyou for your email.&lt;/p&gt;
  </code></pre>