Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function() {
- $('form#contactForm').submit(function() {
- $('form#contactForm .error').remove();
- var hasError = false;
- $('.requiredField').each(function() {
- if(jQuery.trim($(this).val()) == '') {
- var labelText = $(this).prev('label').text();
- $(this).parent().append('<span class="error">You forgot to enter your '+labelText+'.</span>');
- hasError = true;
- } else if($(this).hasClass('email')) {
- var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
- if(!emailReg.test(jQuery.trim($(this).val()))) {
- var labelText = $(this).prev('label').text();
- $(this).parent().append('<span class="error">You entered an invalid '+labelText+'.</span>');
- hasError = true;
- }
- }
- });
- if(!hasError) {
- $('form#contactForm li.buttons button').fadeOut('normal', function() {
- $(this).parent().append('<img src="/wp-content/themes/td-v3/images/template/loading.gif" alt="Loading…" height="31" width="31" />');
- });
- var formInput = $(this).serialize();
- $.post($(this).attr('action'),formInput, function(data){
- $('form#contactForm').slideUp("fast", function() {
- $(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>');
- });
- });
- }
- return false;
- });
- });
- $(document).ready(function(){
- $('.error').hover(function(){
- $('span', this).slideUp(0).stop(true, true).slideDown(500);
- },
- function(){
- $('.error', this).css("display", "block").stop(true, true).delay(100).slideUp(500);
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement