title: Hide form after submit successful
body: <p>Currently I have a contact form working, but I need to hide the form itself after it was send successful. I was thinking of hitting a javascript call when the 'succes' message is run, but I don't know how to do this. </p>
  
  <p>How can I hide the form, but keep the succes message if it's completed?</p>
  
  <p>Thanks in advance!</p>
  
  <pre><code> &lt;?php
    //response generation function
  
    $response = "";
  
    //function to generate response
    function my_contact_form_generate_response($type, $message){
  
      global $response;
  
      if($type == "success") $response = "&lt;div class='success'&gt;{$message}&lt;/div&gt;";
      else $response = "&lt;div class='error'&gt;{$message}&lt;/div&gt;";
  
    }
  
    //response messages
    $not_human       = "&lt;div class='alert alert-danger'&gt;Verificatie incorrect.&lt;/div&gt;";
    $missing_content = "&lt;div class='alert alert-danger'&gt;U heeft niet alle verplichte velden ingevuld&lt;/div&gt;";
    $email_invalid   = "&lt;div class='alert alert-danger'&gt;Incorrect e-mail adres.&lt;/div&gt;";
    $message_unsent  = "&lt;div class='alert alert-danger'&gt;Bericht niet verzonden. Probeer opnieuw.&lt;/div&gt;";
    $message_sent    = "&lt;div class='alert alert-success'&gt;Bedankt, wij nemen binnenkort contact met u op&lt;/div&gt;";
  
    //user posted variables
    $name = $_POST['message_name'];
    $email = $_POST['message_email'];
    $phone = $_POST['message_phone'];
    $message = $_POST['message_text'];
    $human = $_POST['message_human'];
  
    $totalmessage = "
       Naam:       $name \n
       Telefoonnummer:      $phone \n
       E-mail:      $email \n
       Bericht:    $message \n ";
  
    //php mailer variables
    $to = "$curauth-&gt;user_email";
    $subject = "Bel mij terug";
    $headers = 'From: email@email.com' . "\r\n" .
        'Reply-To: email@email.com' . "\r\n" .
        'X-Mailer: PHP/' . phpversion();
  
    if(!$human == 0){
      if($human != 2) my_contact_form_generate_response("error", $not_human); //not human!
      else {
  
        //validate email
        if(!filter_var($email, FILTER_VALIDATE_EMAIL))
          my_contact_form_generate_response("error", $email_invalid);
        else //email is valid
        {
          //validate presence of name and message
          if(empty($name)){
            my_contact_form_generate_response("error", $missing_content);
          }
          else //ready to go!
          {
            $sent = wp_mail($to, $subject, $totalmessage, $headers);
            if($sent) my_contact_form_generate_response("success", $message_sent); //message sent!
            else my_contact_form_generate_response("error", $message_unsent); //message wasn't sent
          }
        }
      }
    }
    else if ($_POST['submitted']) my_contact_form_generate_response("error", $missing_content);
  
  ?&gt;
  
  &lt;div id="respond"&gt;
    &lt;?php echo $response; ?&gt;
    &lt;form action="&lt;?php the_permalink(); ?&gt;" method="post"&gt;
      &lt;p&gt;&lt;label for="name"&gt;Uw naam (verplicht) &lt;span&gt;*&lt;/span&gt; &lt;br&gt;&lt;input type="text" class="wpcf7-form-control wpcf7-text" name="message_name" value="&lt;?php echo esc_attr($_POST['message_name']); ?&gt;"&gt;&lt;/label&gt;&lt;/p&gt;
      &lt;p&gt;&lt;label for="message_phone"&gt;Uw Telefoonnummer (verplicht) &lt;span&gt;*&lt;/span&gt; &lt;br&gt;&lt;input type="text" class="wpcf7-form-control wpcf7-text" name="message_phone" value="&lt;?php echo esc_attr($_POST['message_phone']); ?&gt;"&gt;&lt;/label&gt;&lt;/p&gt;
      &lt;p&gt;&lt;label for="message_email"&gt;Uw e-mail adres: &lt;span&gt;*&lt;/span&gt; &lt;br&gt;&lt;input type="text" name="message_email" class="wpcf7-form-control wpcf7-text" value="&lt;?php echo esc_attr($_POST['message_email']); ?&gt;"&gt;&lt;/label&gt;&lt;/p&gt;
      &lt;p&gt;&lt;label for="message_text"&gt;Uw vraag: &lt;span&gt;&lt;/span&gt; &lt;br&gt;&lt;textarea type="text" name="message_text" class="wpcf7-form-control wpcf7-textarea"&gt;&lt;?php echo esc_textarea($_POST['message_text']); ?&gt;&lt;/textarea&gt;&lt;/label&gt;&lt;/p&gt;
      &lt;p&gt;&lt;label for="message_human"&gt;Verificatie: &lt;span&gt;*&lt;/span&gt; &lt;br&gt;&lt;input type="text" style="width: 60px;" name="message_human"&gt; + 3 = 5&lt;/label&gt;&lt;/p&gt;
      &lt;input type="hidden" name="submitted" class="wpcf7-form-control wpcf7-submit" value="1"&gt;
      &lt;p&gt;&lt;input type="submit"&gt;&lt;/p&gt;
    &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>