var error_msg_2033 = ""; function validate_email_2033(mail) { if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail)) { return (true); } error_msg_2033 = "Имэйл хаягаа зөв оруулна уу"; return (false); } function getCookie_2033(cname) { var name_2033 = cname + "="; var decodedCookie_2033 = decodeURIComponent(document.cookie); var ca_2033 = decodedCookie_2033.split(';'); for(var i = 0; i < ca_2033.length; i++) { var c_2033 = ca_2033[i]; while (c_2033.charAt(0) == ' ') { c_2033 = c_2033.substring(1); } if (c_2033.indexOf(name_2033) == 0) { return c_2033.substring(name_2033.length, c_2033.length); } } return ""; } function subscribe_submit_2033(){ var form_2033 = document.querySelector('#subscribe-form-2033'); var data_2033 = new FormData(form_2033); var url_2033 = "/api.php/subscription/save?site_id=1336&id=2033" + '&cookie_id=' + getCookie_2033("cookie_id") + '&short_cookie_id=' + getCookie_2033("short_cookie_id"); var xhr_2033 = new XMLHttpRequest(); if (window.XMLHttpRequest) { // Mozilla, Safari, ... var xhr_2033 = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE var xhr_2033 = new ActiveXObject("Microsoft.XMLHTTP"); } xhr_2033.open('POST', url_2033, true); xhr_2033.onload = function () { /* do something to response */ console.log(this.responseText); document.getElementById("subscription-form-container-2033").innerHTML = this.responseText; }; var valid_2033 = 1; if(form_2033.querySelector('input[name="subscriber[name]"]')){ if(form_2033.querySelector('input[name="subscriber[name]"]').value.trim().length > 0){ }else{ valid_2033 = 0; form_2033.querySelector('input[name="subscriber[name]"]').setAttribute("style", "border-color: red;"); } } if(form_2033.querySelector('input[name="subscriber[email]"]')){ if(form_2033.querySelector('input[name="subscriber[email]"]').value.trim().length > 0){ }else{ valid_2033 = 0; form_2033.querySelector('input[name="subscriber[email]"]').setAttribute("style", "border-color: red;"); } } if(form_2033.querySelector('input[name="subscriber[phone]"]')){ if(form_2033.querySelector('input[name="subscriber[phone]"]').value.trim().length > 0){ }else{ valid_2033 = 0; form_2033.querySelector('input[name="subscriber[phone]"]').setAttribute("style", "border-color: red;"); } } if(form_2033.querySelector('input[name="subscription[company_name]"]')){ if(form_2033.querySelector('input[name="subscription[company_name]"]').value.trim().length > 0){ }else{ valid_2033 = 0; form_2033.querySelector('input[name="subscription[company_name]"]').setAttribute("style", "border-color: red;"); } } if(form_2033.querySelector('input[name="subscription[company_position]"]')){ if(form_2033.querySelector('input[name="subscription[company_position]"]').value.trim().length > 0){ }else{ valid_2033 = 0; form_2033.querySelector('input[name="subscription[company_position]"]').setAttribute("style", "border-color: red;"); } } if(form_2033.querySelector('input[name="subscription[title]"]')){ if(form_2033.querySelector('input[name="subscription[title]"]').value.trim().length > 0){ }else{ valid_2033 = 0; form_2033.querySelector('input[name="subscription[title]"]').setAttribute("style", "border-color: red;"); } } if(form_2033.querySelector('textarea[name="subscription[body]"]')){ if(form_2033.querySelector('textarea[name="subscription[body]"]').value.trim().length > 0){ }else{ valid_2033 = 0; form_2033.querySelector('textarea[name="subscription[body]"]').setAttribute("style", "border-color: red;"); } } if(valid_2033 == 0){ error_msg_2033 = "Талбаруудыг бүрэн бөглөнө үү!"; } if(!validate_email_2033(form_2033.querySelector('input[name="subscriber[email]"]').value)){ form_2033.querySelector('input[name="subscriber[email]"]').style="border-color: red;"; valid_2033 = 0; }else{ } if(valid_2033){ document.querySelector('#subscribe-form-2033').style.display = "none"; document.querySelector('#subscription-form-loading-2033').style.display = "inline"; xhr_2033.send(data_2033); }else{ alert(error_msg_2033); } } // function postRequest_2033(strURL) { var xmlHttp_2033; if (window.XMLHttpRequest) { // Mozilla, Safari, ... var xmlHttp_2033 = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE var xmlHttp_2033 = new ActiveXObject("Microsoft.XMLHTTP"); } xmlHttp_2033.open('POST', strURL, true); xmlHttp_2033.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlHttp_2033.onreadystatechange = function() { if (xmlHttp_2033.readyState == 4) { updatepage_2033(xmlHttp_2033.responseText); } } xmlHttp_2033.send(strURL); } // function updatepage_2033(str){ document.getElementById("subscription-form-container-2033").innerHTML = str; } //'//salon.estelpro.mn' + var get_url_2033 = '/api.php/subscription/renderform?site_id=1336' + '&id=2033' + '' ; postRequest_2033(get_url_2033);