Advertisement
Guest User

Form submit and button change

a guest
Jan 30th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. jQuery(document).ready(function()
  2. {
  3.     form = jQuery("form#ck_subscribe_form");
  4.  
  5.     if (form.length == 1)
  6.     {
  7.         form.off("submit");
  8.         form.submit(function(e)
  9.         {
  10.             e.stopPropagation();
  11.             e.preventDefault();
  12.  
  13.             var subButton  = form.find("#ck_subscribe_button");
  14.             var btnText    = subButton.text();
  15.             var successMsg = form.parent().find("#ck_success_msg");
  16.             var errorMsg   = form.find("#ck_error_msg");
  17.  
  18.             subButton.prop("disabled", true).text("Joining...");
  19.  
  20.             var showErrorMsg = function()
  21.             {
  22.                 errorMsg.parent("div").css("display", "block");
  23.                 errorMsg.css("opacity", "0").fadeTo(250, 1);
  24.             };
  25.             data = form.serializeArray();
  26.  
  27.             if (!!document.referrer)
  28.             {
  29.                 data.push({ name: "referrer", value: document.referrer});
  30.             }
  31.  
  32.             if (form.find(".optIn").is(":checked")) {
  33.                 data.push({name: "course_opted", value: true});
  34.             }
  35.  
  36.             jQuery.ajax({
  37.                 url: form.attr("action"),
  38.                 data: data,
  39.                 method: "POST",
  40.                 success: function (response)
  41.                 {
  42.                     /* Replace with your thank you page URL */
  43.                     window.location.href = "https://www.website.com/email-success";
  44.                 },
  45.                 error: function (jqXHR, textStatus, errorThrown)
  46.                 {
  47.                     subButton.prop("disabled", false).text(btnText);
  48.                     showErrorMsg();
  49.                 }
  50.             });
  51.         });
  52.     }
  53. });
  54.  
  55.  
  56. jQuery(document).ready(function()
  57. {
  58.     form = jQuery("form#ck_subscribe_form2");
  59.  
  60.     if (form.length == 1)
  61.     {
  62.         form.off("submit");
  63.         form.submit(function(e)
  64.         {
  65.             e.stopPropagation();
  66.             e.preventDefault();
  67.  
  68.             var subButton  = form.find("#ck_subscribe_button2");
  69.             var btnText    = subButton.text();
  70.             var successMsg = form.parent().find("#ck_success_msg");
  71.             var errorMsg   = form.find("#ck_error_msg");
  72.  
  73.             subButton.prop("disabled", true).text("Joining...");
  74.  
  75.             var showErrorMsg = function()
  76.             {
  77.                 errorMsg.parent("div").css("display", "block");
  78.                 errorMsg.css("opacity", "0").fadeTo(250, 1);
  79.             };
  80.             data = form.serializeArray();
  81.  
  82.             if (!!document.referrer)
  83.             {
  84.                 data.push({ name: "referrer", value: document.referrer});
  85.             }
  86.  
  87.             if (form.find(".optIn").is(":checked")) {
  88.                 data.push({name: "course_opted", value: true});
  89.             }
  90.  
  91.             jQuery.ajax({
  92.                 url: form.attr("action"),
  93.                 data: data,
  94.                 method: "POST",
  95.                 success: function (response)
  96.                 {
  97.                     /* Replace with your thank you page URL */
  98.                     window.location.href = "https://www.website.com/email-success";
  99.                 },
  100.                 error: function (jqXHR, textStatus, errorThrown)
  101.                 {
  102.                     subButton.prop("disabled", false).text(btnText);
  103.                     showErrorMsg();
  104.                 }
  105.             });
  106.         });
  107.     }
  108. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement