title: How to Submit a Contact Form and Not Redirect to Another Page
body: <p>I can't find anyone asking a similar question - I built a simply contact form and when I click submit, it takes me to the page on which the php for sending the message is written. I was wondering how I could make this not happen and instead just display a "thank you" message underneath the submit button, or something similar. </p>
  
  <p>I based my code off of this tutorial. <a href="http://www.freecontactform.com/html_form.php" rel="nofollow">http://www.freecontactform.com/html_form.php</a>. The form sends an email fine, but I just don't want it to redirect to another page after submission. </p>
  
  <pre><code>    &lt;form name="helpful-form" method="post" action="../helpful-form.php"&gt; 
          &lt;input type="radio" name="unhelpful" value="The Page Did Not Answer My Questions"&gt;Did Not Answer My Questions&lt;/input&gt;&lt;br&gt;
          &lt;input type="radio" name="unhelpful" value="The Page Content Was Not What I Was Expecting"&gt;&lt;br&gt;
          &lt;input type="radio" name="unhelpful" value="There Was Too Much Information On The Page"&gt;&lt;br&gt;
          &lt;input type="radio" name="unhelpful" value="There Was Too Little Information On The Page"&lt;br&gt;
          &lt;input type="radio" name="unhelpful" value="The Page Content Was Too Complicated"&gt;&lt;br&gt;
          &lt;textarea rows="3" cols="30" name="recommendations"&gt;&lt;/textarea&gt;
          &lt;input type="text" name="email"&gt;Email: (optional) &lt;/input&gt;
          &lt;input type="submit" value="submit" name="submit"&gt;
        &lt;/form&gt;
  </code></pre>
  
  <p><strong>helpful-form.php</strong></p>
  
  <pre><code>  &lt;?php 
  
      $email_to = "*******************";
      $email_subject = "Website Recommendation/Question - Form Submission";
  
      function died($error) {
          echo ($error);
          die();
      }
  
      function clean_string($string) {
          $bad = array("content-type","bcc:","to:","cc:","href");
          return str_replace($bad,"",$string);
      }
  
      if (!isset($_POST['unhelpful']) &amp;&amp; !isset($_POST['recommendations'])) {
          died('Please Select A Reason Why This Page Is Unhelpful.');
      }
  
          $unhelpful = $_POST['unhelpful'];
          $recommendations = $_POST['recommendations'];
          $email = $_POST['email'];
  
      $email_message = "A new website recommendation and/or question has been submitted from BestAttorney.com:\n";
  
  
  
      $email_message .= "This page was not helpful because: ".clean_string($unhelpful)."\n";
      $email_message .= "Other Comments from the User: ".clean_string($recommendations)."\n";
      $email_message .= "This Form Was Submitted by: ".clean_string($email)."\n";
  
      $headers = 'From: '.$email."\r\n".
      'Reply-To: '.$email."\r\n" . 
      'X-Mailer: PHP/' . phpversion();
      @mail($email_to, $email_subject, $email_message, $headers); 
  ?&gt;
  
  Thank you giving us your recommendations! We will respond to any questions you had in a timely manner. 
  
  &lt;?php die(); ?&gt; 
  </code></pre>
  
  <p>I am also aware that there is more I have to do to make sure that the form is more secure but for now I'd like to just get this fixed up. Any thoughts? Thanks guys!</p>