$( () => { $.ajax({ cache: false, url: '/blog/ajax/get-tilda-params/', data: { 'slug': $('#post_slug').val(), }, success: (data) => { let ip = data.ip; let postId = data.post_id; $('form').on('submit', function () { $('input[name="ip"]').val(ip); $('input[name="post_id"]').val(postId); return true; }); let observer = new MutationObserver(() => { let ipNode = $('input[name="ip"]'); let postIdNode = $('input[name="post_id"]'); if (ipNode.length) { ipNode.val(ip); } if (postIdNode.length) { postIdNode.val(postId); } }); observer.observe(document.body, { childList: true, subtree: true, characterDataOldValue: true }); } }); $('input[name=lead_channel_id]').closest('.js-form-proccess') .removeClass("js-form-proccess") .addClass('js-form-c-proccess'); initOrdersObserver(); $(".r").on("click", ".js-form-c-proccess [type=submit]", sendOrder); }); /** * Custom send data from orders */ function sendOrder(e) { e.preventDefault(); let self = $(this); if (self.data("form-sending-status") >= '1') { return false; } if ($(this).hasClass("t706__submit_disable")) { return false; } let valid; let form = $(this).closest("form"); if (form.length === 0) { return false; } if (self.addClass("t-btn_sending"), self.data("form-sending-status", "1"), self.data("submitform", form), window.tildaForm.hideErrors(form), valid = window.tildaForm.validate(form), window.tildaForm.showErrors(form, valid) ) { return self.removeClass("t-btn_sending"), self.data("form-sending-status", "0"), self.data("submitform", ""), false; } let formType = form.data("formactiontype"); valid = $("#allrecords").data("tilda-formskey"); if (form.find(".js-formaction-services").length === 0 && formType !== 1 && valid === '') { let errors = form.find(".js-errorbox-all"); if (!errors || errors.length === 0) { form.prepend('
'); errors = form.find(".js-errorbox-all"); } let ruleErrors = errors.find(".js-rule-error-all"); return ruleErrors && ruleErrors.length !== 0 || (errors.append('' + json.error + "
"), ruleErrors = errors.find(".js-rule-error-all")), ruleErrors.html("Please set receiver in block with forms").show(), errors.show(), form.addClass("js-send-form-error"), self.removeClass("t-btn_sending"), self.data("form-sending-status", "0"), self.data("submitform", ""), form.trigger("tildaform:aftererror"), false } let data = form.serializeArray(); data.push({ name: "formid", value: form.attr("id") }); data.push({ name: "COOKIES", value: document.cookie }); $.ajax({ type: "POST", url: 'https://' + location.host.replace('-blog', '') + '/api_tilda/create_order_by_data/', data: data, dataType: "text", xhrFields: { withCredentials: false }, success: function (response) { let successUrl = form.data("success-url"), successCallback = form.data("success-callback"); // for tilda process run: window.tildaForm.send(form, self, formType, valid); window.tildaForm.successEnd(form, successUrl, successCallback); } }); return false; } /** * Observer for change class in forms for custom event */ function initOrdersObserver() { const config = { attributes: false, childList: true, subtree: true }; const tags = ['DIV', 'FORM']; let callback = (mutationList, observer) => { mutationList.forEach( (mutation) => { if (tags.includes(mutation.target.tagName)) { let formIn = $(mutation.target).find('form'); if (formIn.length) { formIn.find('input[name=lead_channel_id]').closest('.js-form-proccess') .removeClass("js-form-proccess") .addClass('js-form-c-proccess'); } } }); }; let observer = new MutationObserver(callback); let container = document.documentElement || document.body; observer.observe(container, config); }