$(document).ready(function(){ $('form#regform').validate({ onKeyup : true, sendForm : false, onChange: true, eachValidField : function() { var $this = $(this); if($this.closest('div').hasClass('control-mwr')){ var $wr = $this.closest('div'); $wr.removeClass('error').addClass('success'); $wr.children('.control-message').html(''); } }, eachInvalidField : function($form, $e) { var $t; var $this = $(this); for($t in $e){ if(!$e[$t]){ var $message = $this.data($t+'-message'); if(typeof $message == 'string'){ if(!$this.closest('div').hasClass('control-mwr')){ $this.wrap('
'); } var $wr = $this.closest('div'); $wr.removeClass('success').addClass('error'); if($wr.children('.control-message').length == 0){ $wr.append('
'+$message+'
'); }else{ $wr.children('.control-message').html($message); } } } } }, }); $('form#regform').submit(function(){ var $thisForm = $(this); var $url = $thisForm.attr('action'); if($thisForm.hasClass('waitting')){ return false; } $thisForm.addClass('waitting'); $.ajax({ type: "POST", url: $url, data: $thisForm.serialize(), dataType: 'JSON', success: function($response) { if($response.status == 'login'){ window.location.reload(); }else{ var $alertModal = $('#alertModal'); $alertModal.find('.modal-message').html($response.message); $alertModal.modal('show'); } $thisForm.removeClass('waitting'); } }); return false; }); });