You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.5 KiB
56 lines
1.5 KiB
$("#contactForm").validator().on("submit", function (event) { |
|
if (event.isDefaultPrevented()) { |
|
// handle the invalid form... |
|
formError(); |
|
submitMSG(false, "请完整填写!"); |
|
} else { |
|
// everything looks good! |
|
event.preventDefault(); |
|
submitForm(); |
|
} |
|
}); |
|
|
|
|
|
function submitForm(){ |
|
// Initiate Variables With Form Content |
|
var name = $("#name").val(); |
|
var email = $("#email").val(); |
|
var msg_subject = $("#msg_subject").val(); |
|
var message = $("#message").val(); |
|
|
|
|
|
$.ajax({ |
|
type: "POST", |
|
url: "../phpmailer/mail.php", |
|
data: "type=主页反馈信息&name=" + name + "&email=" + email + "&subject=" + msg_subject + "&message=" + message, |
|
success : function(text){ |
|
if (text = "success"){ |
|
formSuccess(); |
|
} else { |
|
formError(); |
|
submitMSG(false,text); |
|
} |
|
} |
|
}); |
|
} |
|
|
|
function formSuccess(){ |
|
$("#contactForm")[0].reset(); |
|
submitMSG(true, "提交成功!") |
|
} |
|
|
|
function formError(){ |
|
$("#contactForm").removeClass().addClass('shake animated').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){ |
|
$(this).removeClass(); |
|
}); |
|
} |
|
|
|
function submitMSG(valid, msg){ |
|
if(valid){ |
|
var msgClasses = "h3 text-left tada animated text-success"; |
|
} else { |
|
var msgClasses = "h3 text-left text-danger"; |
|
} |
|
|
|
$("#msgSubmit").removeClass().addClass(msgClasses).text(msg); |
|
} |