title: Disable "submit" button after form validation and submission. PHP, JQ?
body: <p>I have a contact-template.php file from wordpress...</p>
  
  <p>The form has 4 required fields...</p>
  
  <p>Right now, if any or all required fields are blank, the form will not submit and the user will get "This field is required" message below each text input field that is blank.
   - this is functioning exactly how I want it to</p>
  
  <p>The problem I am having is when the required fields are filled, and the "submit" button is clicked, there is a 10-15 second pause before the "Thank you, we'll get back to you as soon as possible" message displays...</p>
  
  <p>because of this pause, users are clicking the submit button multiple times and it is sending a duplicate email for every click.</p>
  
  <p>I have tried using "onclick="this.disabled=true;this.value='Sending, please wait...", but this skips the input field validation and does not allow the message to be sent.</p>
  
  <p>I want this button to disable and display "sending, please wait..." text, but it needs to validate text input fields and ultimately submit/send the email message</p>
  
  <p>PLEASE HELP!!!</p>
  
  <p>Here is the code...</p>
  
  <pre><code>&lt;?php /* Template Name: Contact Form */ ?&gt;
  
  
  &lt;?php get_header(); ?&gt;
  &lt;div id="top-div"&gt;&lt;/div&gt;
  
  &lt;div id="container"&gt;
  &lt;div id="inner-headline"&gt;
      &lt;h2&gt; 
          &lt;?php 
              $headline = get_post_meta($post-&gt;ID, "_headline", $single = false);
              if(!empty($headline[0]) )
              {
                  echo $headline[0];
              }
              else
              {
                  the_title();
              }
          ?&gt;
      &lt;/h2&gt;
  &lt;/div&gt;
  &lt;div id="content"&gt;      
      &lt;div id="content-inner"&gt;
          &lt;div class="sideright-left-col"&gt;
  
              &lt;?php if (have_posts()) : ?&gt;
  
                  &lt;?php while (have_posts()) : the_post(); ?&gt;
  
                   &lt;?php the_content(); ?&gt;
  
                      &lt;?php if(isset($hasError) || isset($captchaError)): 
  ?&gt;
                          &lt;p class="error"&gt;&lt;?php _e('There was an error 
  submitting the form.', 'Sona')?&gt;&lt;p&gt;
                      &lt;?php endif ?&gt;
                      &lt;div id="status"&gt;&lt;/div&gt;
                      &lt;form action="" id="contact-form" method="post"&gt;
  
                          &lt;div class="name"&gt;
                              &lt;label for="contactName"&gt;&lt;span style="color: 
  red;"&gt;*&amp;nbsp&lt;/span&gt;&lt;?php _e( 'Name', 'Sona' ); ?&gt;:&lt;/label&gt;
                              &lt;input type="text" name="contactName" 
  id="contactName" value="&lt;?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?&gt;" 
  class="requiredField txt"/&gt;
  
                              &lt;?php if(isset($nameError) &amp;&amp; $nameError != ''): ?&gt;
  &lt;span class="error"&gt;&lt;?php echo $nameError;?&gt;&lt;/span&gt;&lt;?php endif;?&gt;
  
                              &lt;div class="clear"&gt;&lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="email"&gt;
                              &lt;label for="email"&gt;&lt;span style="color: 
  red;"&gt;*&amp;nbsp&lt;/span&gt;&lt;?php _e( 'E-mail', 'Sona' ); ?&gt;:&lt;/label&gt;
                              &lt;input type="text" name="email" id="email" value="&lt;?php 
  if(isset($_POST['email'])) echo $_POST['email'];?&gt;" class="requiredField email txt" /&gt;
  
                              &lt;?php if(isset($emailError) &amp;&amp; 
  $emailError != ''): ?&gt;&lt;span class="error"&gt;&lt;?php echo $emailError;?&gt;&lt;/span&gt;&lt;?php endif;?&gt;
  
                              &lt;div class="clear"&gt;&lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="subject"&gt;
                              &lt;label for="subject"&gt;&lt;span style="color: 
  red;"&gt;*&amp;nbsp&lt;/span&gt;&lt;?php _e( 'Subject', 'Sona' ); ?&gt;:&lt;/label&gt;
                              &lt;input type="text" name="subject" id="subject" value="&lt;?
  php if(isset($_POST['subject'])) echo $_POST['subject'];?&gt;" class="requiredField txt"/&gt;
  
                              &lt;?php if(isset($subjectError) &amp;&amp; $subjectError != ''): ?
  &gt;&lt;span class="error"&gt;&lt;?php echo $subjectError;?&gt;&lt;/span&gt;&lt;?php endif;?&gt;
  
                              &lt;div class="clear"&gt;&lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="clear"&gt;&lt;/div&gt;
                          &lt;div class="message"&gt;
                              &lt;label for="message"&gt;&lt;span style="color: 
  red;"&gt;*&amp;nbsp&lt;/span&gt;&lt;?php _e( 'Message', 'Sona' ); ?&gt;:&lt;/label&gt;
                              &lt;textarea name="message" cols="100" rows="200" 
  id="message" class="txt requiredField"&gt;&lt;?php echo isset($_POST['message']) &amp;&amp; 
  $_POST['message']!=''  
  ?  stripslashes($_POST['message'])  : ''?&gt;&lt;/textarea&gt;
  
                              &lt;?php if(isset($messageError) &amp;&amp; 
  $messageError != '') { ?&gt;&lt;span class="error"&gt;&lt;?php echo $messageError;?&gt;&lt;/span&gt; &lt;?php } ?&gt;
  
                              &lt;div class="clear"&gt;&lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div&gt;
                              &lt;?php 
                                  $al_options = 
  get_option('al_general_settings'); 
                                  $options = array( 
  
  $al_options['al_contact_error_message'], 
  
  $al_options['al_contact_success_message'],
  
  $al_options['al_subject'],
  
  $al_options['al_email_address'],
                                                  );
                              ?&gt;
                              &lt;input type="hidden" name = "options" value="&lt;?php 
  echo implode(',', $options) ?&gt;" /&gt;
                              &lt;input type="hidden" name="siteurl" value="&lt;?php 
  echo get_option('blogname')?&gt;" /&gt;
                          &lt;br /&gt;
                              &lt;input type="submit" class="button white-back" 
  value="Submit Message" tabindex="5" id="submit" name="send"/&gt;
  
                               &lt;div class="clear"&gt;&lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/form&gt;
                  &lt;/div&gt;
                  &lt;div class="sideright-right-col"&gt;
                      &lt;?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("Contact 
  Sidebar") ) : ?&gt; &lt;?php   endif;?&gt;
                  &lt;/div&gt;  
                  &lt;div class="clear"&gt;&lt;/div&gt;
              &lt;/div&gt;
              &lt;/div&gt;
  
         &lt;/div&gt;
  &lt;!-- END CONTENT --&gt;
  &lt;/div&gt;
  &lt;?php endwhile; ?&gt;
  &lt;?php endif; ?&gt;
  &lt;script type="text/javascript"&gt;
  
  jQuery(document).ready(function(){
  jQuery("#contact-form").validate({
  submitHandler: function() {
  
      var postvalues =  jQuery("#contact-form").serialize();
  
  
      jQuery.ajax
       ({
         type: "POST",
         url: "&lt;?php echo get_template_directory_uri() ?&gt;/contact-form.php",
         data: postvalues,
         success: function(response)
         {
           jQuery("#status").addClass('success-
  message').html(response).show('normal');
           jQuery('#contact-form :input.not("#send")').val("");
           jQuery('#contact-form :textarea').val("");
         }
       });
      return false;
  
  },
  focusInvalid: true,
  focusCleanup: false,
  rules: 
  {
      contactName: {required: true},
      email: {required: true, minlength: 6,maxlength: 50, email:true},
      message: {required: true},
      subject: {required: true}
  },
  
  messages: 
  {
      contactName: {required: "&lt;?php _e( 'This field is required', 'Sona' ); ?&gt;"},
      email: {required: "&lt;?php _e( 'This field is required', 'Sona' ); ?&gt;", email: "&lt;?php         
  _e( 'Please provide a valid e-mail address.', 'Sona' ); ?&gt;"},
      message: {required: "&lt;?php _e( 'This field is required', 'Sona' ); ?&gt;"},
      subject: {required: "&lt;?php _e( 'This field is required', 'Sona' ); ?&gt;"} 
  },
  
  errorPlacement: function(error, element) 
  {
      error.insertAfter(element);
  },
  invalidHandler: function()
  {
      jQuery("body").animate({ scrollTop: 0 }, "slow");
  }
  });
  });
  
  
  &lt;/script&gt;
  
  &lt;?php get_footer(); ?&gt;   
  </code></pre>