Add Validation to Contact Form
December 17, 2010 at 1:21 pm | Blog | 2 comments
A PengbosInspiration theme user asked for validation on contact form, especially for the email field. It should be a very common request for developers using contact form. I made a little change to the javascript codes.
the original javascript code for submitting a contact form is as follow:
var theme_template_dir = jQuery("meta[name=theme_template_dir]").attr('content'); jQuery(document).ready(function(){ jQuery('<div></div>') .insertBefore('#log') .attr('id','log_wait') .css('display','none') .addClass('ajax-loading') .ajaxStart(function(){jQuery(this).show();}) .ajaxStop(function(){jQuery(this).hide();}); jQuery('#contacts').submit(function() { jQuery.post(theme_template_dir + '/include/gmail_sendmail.php',jQuery(this).serialize(), function(data){ jQuery('#log').empty(); jQuery('<div></div>') .attr('id','log_res') .appendTo('#log') .html(data); }); return false; }); }); |


