tech4biz/assets/js/contact-form-script.js
2024-10-24 17:20:08 +05:30

69 lines
2.3 KiB
JavaScript

(function ($) {
"use strict";
// $("#contactForms").validator().on("submit", function (event) {
// if (event.isDefaultPrevented()) {
// formError();
// submitMSG(false, "Did you fill up the form properly?");
// } else {
// event.preventDefault();
// submitForm();
// }
// });
$("#contactForms").validator().on("submit", function (event) {
var name = $("#name").val();
var email = $("#emailid").val();
var msg_subject = $("#subject").val();
var phone_number = $("#contact").val();
var message = $("#message").val();
if (name == "" || email == "" || msg_subject == "" || phone_number == "" || message == "") {
formError();
submitMSG(false, "Did you fill up the form properly?");
}
else {
event.preventDefault();
submitForm();
window.location.reload();
}
});
function submitForm() {
var name = $("#name").val();
var email = $("#emailid").val();
var msg_subject = $("#subject").val();
var phone_number = $("#contact").val();
var message = $("#message").val();
$.ajax({
type: "POST",
url: "admin/api/add_contact_us.php",
data: "name=" + name + "&emailid=" + email + "&subject=" + msg_subject + "&contact=" + phone_number + "&message=" + message,
success: function (text) {
if (text == "success") {
formSuccess();
} else {
formError();
submitMSG(false, text);
}
}
});
}
function formSuccess() {
$("#contactForms")[0].reset();
submitMSG(true, "Message Submitted!")
}
function formError() {
$("#contactForms").removeClass().addClass('shake animated').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function () {
$(this).removeClass();
});
}
function submitMSG(valid, msg) {
if (valid) {
var msgClasses = "h4 tada animated text-success";
} else {
var msgClasses = "h4 text-danger";
}
$("#msgSubmit").removeClass().addClass(msgClasses).text(msg);
}
}(jQuery));