Advertisement
keihead

contact-js

Jul 17th, 2013
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function() {
  2.     $('form#contactForm').submit(function() {
  3.         $('form#contactForm .error').remove();
  4.         var hasError = false;
  5.         $('.requiredField').each(function() {
  6.             if(jQuery.trim($(this).val()) == '') {
  7.                 var labelText = $(this).prev('label').text();
  8.                 $(this).parent().append('<span class="error">You forgot to enter your '+labelText+'.</span>');
  9.                 hasError = true;
  10.             } else if($(this).hasClass('email')) {
  11.                 var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
  12.                 if(!emailReg.test(jQuery.trim($(this).val()))) {
  13.                     var labelText = $(this).prev('label').text();
  14.                     $(this).parent().append('<span class="error">You entered an invalid '+labelText+'.</span>');
  15.                     hasError = true;
  16.                 }
  17.             }
  18.         });
  19.         if(!hasError) {
  20.             $('form#contactForm li.buttons button').fadeOut('normal', function() {
  21.                 $(this).parent().append('<img src="/wp-content/themes/td-v3/images/template/loading.gif" alt="Loading&hellip;" height="31" width="31" />');
  22.             });
  23.             var formInput = $(this).serialize();
  24.             $.post($(this).attr('action'),formInput, function(data){
  25.                 $('form#contactForm').slideUp("fast", function() {                 
  26.                     $(this).before('<p class="thanks"><strong>Thanks!</strong> Your email was successfully sent. I check my email all the time, so I should be in touch soon.</p>');
  27.                 });
  28.             });
  29.         }
  30.        
  31.         return false;
  32.  
  33.     });
  34. });
  35. $(document).ready(function(){
  36.         $('.error').hover(function(){
  37.             $('span', this).slideUp(0).stop(true, true).slideDown(500);
  38.         },
  39.         function(){
  40.             $('.error', this).css("display", "block").stop(true, true).delay(100).slideUp(500);
  41.         });
  42.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement