title: Clear form field after submit
body: <p>I have read other answers for the same question but I am having problems and would be grateful for some advice. 
  I have javaScript in my html file, and an Onclick() statement on the submit button to clear the form but now the email confirmation message does not come up and the message is no longer sent.  If I put the onClick(); in the body of the form, every field is cleared just by clicking on a form field.  I really want to be able to submit a message, then have the form cleared on successful send.</p>
  
  <pre><code>   &lt;script type ="text/javascript"&gt; 
              function clearform () {
   document.getElementById("name").value="";
   document.getElementById("email").value="";
   document.getElementById("subject").value="";
   document.getElementById("message").value="";
  }
  &lt;/script&gt;
  
              &lt;div class="row"&gt;
                  &lt;div class="col-sm-6"&gt;
                      &lt;h2&gt;Send us a message&lt;/h2&gt;
                      &lt;!-- action="replace it with active link."--&gt;
                      &lt;form action="contact.php" method="post" name="contact-form" id="contact-form" &gt;
                          &lt;label for="name"&gt;Your Name &lt;span&gt;*&lt;/span&gt;&lt;/label&gt;
                          &lt;input type="text" name="name" id="name" value="" required /&gt;
                          &lt;label for="email"&gt;Your E-Mail &lt;span&gt;*&lt;/span&gt;&lt;/label&gt;
                          &lt;input type="text" name="email" id="email" value="" required /&gt;
                          &lt;label for="subject"&gt;Subject&lt;/label&gt;
                          &lt;input type="text" name="subject" id="subject" value="" /&gt;
                          &lt;label for="message"&gt;Your Message&lt;/label&gt;
                          &lt;textarea name="message" id="message"&gt;&lt;/textarea&gt;
                          &lt;div class="row"&gt;
                              &lt;div class="col-sm-6"&gt;
                                  &lt;input type="submit" name="sendmessage" id="sendmessage" value="Submit" onclick="clearform();" /&gt;
                              &lt;/div&gt;
                              &lt;div class="col-sm-6 dynamic"&gt;&lt;/div&gt;
                          &lt;/div&gt;
                          &lt;/form&gt;
  </code></pre>
  
  <p>I then have the following in the PHP file:</p>
  
  <pre><code>    private function sendEmail(){
      $mail = mail($this-&gt;email_admin, $this-&gt;subject, $this-&gt;message,
           "From: ".$this-&gt;name." &lt;".$this-&gt;email."&gt;\r\n"
          ."Reply-To: ".$this-&gt;email."\r\n"
      ."X-Mailer: PHP/" . phpversion());
  
      if($mail)
      {
          $this-&gt;response_status = 1;
          //$this-&gt;response_html = '&lt;p&gt;Thank You!&lt;/p&gt;';
      }
  }
  
  
  function sendRequest(){
      $this-&gt;validateFields();
      if($this-&gt;response_status)
      {
          $this-&gt;sendEmail();
      }
  
      $response = array();
      $response['status'] = $this-&gt;response_status;   
      $response['html'] = $this-&gt;response_html;
  
      echo "&lt;span class=\"alert alert-success\" &gt;Your message has been received. Thanks!&lt;/span&gt;";
      header("Location: contact.php");// redirect back to your contact form
      exit;
  
  
     }
  
  }
  
  
  $contact_form = new Contact_Form($_POST, $admin_email, $message_min_length);
  $contact_form-&gt;sendRequest();
  
  ?&gt;
  </code></pre>