if (typeof window.$ === 'undefined') { window.$ = jQuery; } $(document).ready(function bpm_init_form() { const url = 'https://www.leader.online/leader/post/post.php'; const isLeaderEnabled = url.indexOf('leader') > -1; const formIDsToIgnore = ['whatsapp-form', 'form_track-submission']; $('form').each((_, form) => { if (formIDsToIgnore.includes(form.id)) { return; } form = $(form); form.attr('action', url); let retURLInput = form.find('[name="retURL"]'); if (retURLInput.length === 0) { console.log('WARNING: Missing retURL field in lead gen form, using fallback!'); retURLInput = $('').attr('name', 'retURL').attr('type', 'hidden').val('https://www.bpm-music.com/thank-you-yeoz-limudim/'); form.append(retURLInput); } if (isLeaderEnabled) { insert_leader_inputs(form); form.submit((e) => { e.preventDefault(); e.stopImmediatePropagation(); const submitButton = form.find('[type="submit"]'); const originalButtonStyle = { backgroundColor: submitButton.css('background-color'), color: submitButton.css('color'), text: submitButton.text() }; let buttonTextFunction = 'text'; if (!originalButtonStyle.text) { originalButtonStyle.text = submitButton.val(); buttonTextFunction = 'val'; } submitButton .attr('disabled', true) .css('background-color', 'rgba(150, 150, 150, 0.7)') .css('color', 'lightgrey'); let submittingText = ''; const pageLanguage = $('html').attr('lang'); const isArabicLandingPage = window.location.hostname.indexOf('bpm-ar') > -1; if (pageLanguage) { if (pageLanguage.indexOf('ar') > -1 || isArabicLandingPage) { submittingText = 'إرسال'; } else if (pageLanguage.indexOf('en') > -1) { submittingText = 'Submitting...'; } } if (!submittingText) { submittingText = 'שולח...'; } submitButton[buttonTextFunction](submittingText); // Convert '1'/'0' to 'true'/'false'. $('form [type="checkbox"]').each(function (_, checkbox) { checkbox.value = checkbox.checked; }); const formData = new FormData(form[0]); if (!formData.get('last_name')) { formData.set('last_name', '[לא סופק]'); } if (!formData.get('Interests__c')) { formData.set('Interests__c', 'לא ידוע'); } let url = formData.get('theurl'); if (url.includes('?')) { url = url.substring(0, url.indexOf('?')); } formData.set('00N2400000IP3Oj', url); let phoneFieldName = 'phone'; let phone = formData.get(phoneFieldName); if (!phone) { let phoneElement = form.find('[type="tel"]'); phoneFieldName = phoneElement.attr('name'); phone = formData.get(phoneFieldName); } formData.set('phone', phone.replace('+', '%2B')); fetch(form.attr('action'), { method: 'POST', body: formData }).then((response) => { if (response.ok) { window.location.href = retURLInput.val(); } else { alert('מצטערים - לא הצלחנו לשמור את הפרטים שלך. ניתן לפנות אלינו טלפונית, בוואטסאפ או לשלוח מייל עם הפרטים לכתובת: service@bpm-music.com'); submitButton .attr('disabled', false) .css('background-color', originalButtonStyle.backgroundColor) .css('color', originalButtonStyle.color); submitButton[buttonTextFunction](originalButtonStyle.text); } }); }); } }); if (isLeaderEnabled) { if (typeof set_leader_inputs === 'undefined') { console.warn('Leader integration is expected but it looks like the Leader plugin is not installed on this site, or they made a breaking change to their code!'); } else { set_leader_inputs(gt_cc_utm_source); } } function insert_leader_inputs(form) { const leaderFieldsContainer = document.createElement('div'); leaderFieldsContainer.id = 'hidden-leader-fields'; leaderFieldsContainer.style.display = 'none'; const campaignId = document.createElement('input'); campaignId.type = 'hidden'; campaignId.name = 'campaignid'; campaignId.value = '11162'; const campaignPass = document.createElement('input'); campaignPass.type = 'hidden'; campaignPass.name = 'campaignpass'; campaignPass.value = 'vObxotkkpJ'; leaderFieldsContainer.appendChild(campaignId); leaderFieldsContainer.appendChild(campaignPass); const utmSource = document.createElement('input'); utmSource.name = 'utm_source'; utmSource.className = 'utm_class_leader'; leaderFieldsContainer.appendChild(utmSource); const fields = [ 'utm_medium', 'utm_term', 'utm_campaign', 'utm_content', 'content_site', 'gclid', 'fbclid', 'cid', 'AgId', 'AdPos', 'device', 'GeoLoc', 'lp', 'ga4_tid', 'ga4_cid', 'fbq_account', 'fbq_client', 'fbq_time', 'theurl', 'page_title' ]; for (let field of fields) { const fieldInput = document.createElement('input'); fieldInput.type = 'hidden'; fieldInput.name = field; leaderFieldsContainer.appendChild(fieldInput); } form.append(leaderFieldsContainer); } });