Advertisement
Guest User

Untitled

a guest
Sep 26th, 2016
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $("#contactForm").validator().on("submit", function (event) {
  2.     if (event.isDefaultPrevented()) {
  3.         // handle the invalid form...
  4.         formError();
  5.         submitMSG(false, "Did you fill in the form properly?");
  6.     } else {
  7.         // everything looks good!
  8.         event.preventDefault();
  9.         submitForm();
  10.     }
  11. });
  12.  
  13.  
  14. function submitForm(){
  15.     // Initiate Variables With Form Content
  16.     var name = $("#name").val();
  17.     var email = $("#email").val();
  18.     var msg_subject = $("#msg_subject").val();
  19.     var message = $("#message").val();
  20.  
  21.  
  22.     $.ajax({
  23.         type: "POST",
  24.         url: "assets/php/form-process.php",
  25.         data: "name=" + name + "&email=" + email + "&msg_subject=" + msg_subject + "&message=" + message,
  26.         success : function(text){
  27.             if (text == "success"){
  28.                 formSuccess();
  29.             } else {
  30.                 formError();
  31.                 submitMSG(false,text);
  32.             }
  33.         }
  34.     });
  35. }
  36.  
  37. function formSuccess(){
  38.     $("#contactForm")[0].reset();
  39.     submitMSG(true, "ŁĄŻ")
  40. }
  41.  
  42. function formError(){
  43.     $("#contactForm").removeClass().addClass('shake animated').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){
  44.         $(this).removeClass();
  45.     });
  46. }
  47.  
  48. function submitMSG(valid, msg){
  49.     if(valid){
  50.         var msgClasses = "h3 text-center tada animated text-success";
  51.     } else {
  52.         var msgClasses = "h3 text-center text-danger";
  53.     }
  54.     $("#msgSubmit").removeClass().addClass(msgClasses).text(msg);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement