var error_msg_2001 = ""; function validate_email_2001(mail) { if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail)) { return (true); } error_msg_2001 = "Имэйл хаягаа зөв оруулна уу"; return (false); } function getCookie_2001(cname) { var name_2001 = cname + "="; var decodedCookie_2001 = decodeURIComponent(document.cookie); var ca_2001 = decodedCookie_2001.split(';'); for(var i = 0; i < ca_2001.length; i++) { var c_2001 = ca_2001[i]; while (c_2001.charAt(0) == ' ') { c_2001 = c_2001.substring(1); } if (c_2001.indexOf(name_2001) == 0) { return c_2001.substring(name_2001.length, c_2001.length); } } return ""; } function subscribe_submit_2001(){ var form_2001 = document.querySelector('#subscribe-form-2001'); var data_2001 = new FormData(form_2001); var url_2001 = "/api.php/subscription/save?site_id=1307&id=2001" + '&cookie_id=' + getCookie_2001("cookie_id") + '&short_cookie_id=' + getCookie_2001("short_cookie_id"); var xhr_2001 = new XMLHttpRequest(); if (window.XMLHttpRequest) { // Mozilla, Safari, ... var xhr_2001 = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE var xhr_2001 = new ActiveXObject("Microsoft.XMLHTTP"); } xhr_2001.open('POST', url_2001, true); xhr_2001.onload = function () { /* do something to response */ console.log(this.responseText); document.getElementById("subscription-form-container-2001").innerHTML = this.responseText; }; var valid_2001 = 1; if(form_2001.querySelector('input[name="subscriber[name]"]')){ if(form_2001.querySelector('input[name="subscriber[name]"]').value.trim().length > 0){ }else{ valid_2001 = 0; form_2001.querySelector('input[name="subscriber[name]"]').setAttribute("style", "border-color: red;"); } } if(form_2001.querySelector('input[name="subscriber[email]"]')){ if(form_2001.querySelector('input[name="subscriber[email]"]').value.trim().length > 0){ }else{ valid_2001 = 0; form_2001.querySelector('input[name="subscriber[email]"]').setAttribute("style", "border-color: red;"); } } if(form_2001.querySelector('input[name="subscriber[phone]"]')){ if(form_2001.querySelector('input[name="subscriber[phone]"]').value.trim().length > 0){ }else{ valid_2001 = 0; form_2001.querySelector('input[name="subscriber[phone]"]').setAttribute("style", "border-color: red;"); } } if(form_2001.querySelector('input[name="subscription[company_name]"]')){ if(form_2001.querySelector('input[name="subscription[company_name]"]').value.trim().length > 0){ }else{ valid_2001 = 0; form_2001.querySelector('input[name="subscription[company_name]"]').setAttribute("style", "border-color: red;"); } } if(form_2001.querySelector('input[name="subscription[company_position]"]')){ if(form_2001.querySelector('input[name="subscription[company_position]"]').value.trim().length > 0){ }else{ valid_2001 = 0; form_2001.querySelector('input[name="subscription[company_position]"]').setAttribute("style", "border-color: red;"); } } if(form_2001.querySelector('input[name="subscription[title]"]')){ if(form_2001.querySelector('input[name="subscription[title]"]').value.trim().length > 0){ }else{ valid_2001 = 0; form_2001.querySelector('input[name="subscription[title]"]').setAttribute("style", "border-color: red;"); } } if(form_2001.querySelector('textarea[name="subscription[body]"]')){ if(form_2001.querySelector('textarea[name="subscription[body]"]').value.trim().length > 0){ }else{ valid_2001 = 0; form_2001.querySelector('textarea[name="subscription[body]"]').setAttribute("style", "border-color: red;"); } } if(valid_2001 == 0){ error_msg_2001 = "Талбаруудыг бүрэн бөглөнө үү!"; } if(!validate_email_2001(form_2001.querySelector('input[name="subscriber[email]"]').value)){ form_2001.querySelector('input[name="subscriber[email]"]').style="border-color: red;"; valid_2001 = 0; }else{ } if(valid_2001){ document.querySelector('#subscribe-form-2001').style.display = "none"; document.querySelector('#subscription-form-loading-2001').style.display = "inline"; xhr_2001.send(data_2001); }else{ alert(error_msg_2001); } } // function postRequest_2001(strURL) { var xmlHttp_2001; if (window.XMLHttpRequest) { // Mozilla, Safari, ... var xmlHttp_2001 = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE var xmlHttp_2001 = new ActiveXObject("Microsoft.XMLHTTP"); } xmlHttp_2001.open('POST', strURL, true); xmlHttp_2001.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlHttp_2001.onreadystatechange = function() { if (xmlHttp_2001.readyState == 4) { updatepage_2001(xmlHttp_2001.responseText); } } xmlHttp_2001.send(strURL); } // function updatepage_2001(str){ document.getElementById("subscription-form-container-2001").innerHTML = str; } //'//ikhbodi.mn' + var get_url_2001 = '/api.php/subscription/renderform?site_id=1307' + '&id=2001' + '' ; postRequest_2001(get_url_2001);