function getCookie(cname) {
let name = cname + „=“;
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(‚;‘);
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function setHiddenFormData(name, value) {
let selector = "input[name='" + name + "']";
let element = document.querySelector(selector);
if (!element) {
console.warn(`Element with name '${name}' not found`);
return;
}
let existing = element.value;
if (!existing) {
element.value = value;
}
}
function setUTMFormData(name) {
setHiddenFormData(name, getCookie(name));
}
let redirectUrl = 'https://nilohealth.com/de/thank-you/';
let redirectUrls = {
'': 'https://nilohealth.com/de/thank-you/',
'0-50': 'https://nilohealth.com/de/thank-you-with-calendar-50/',
'50-100': 'https://nilohealth.com/de/thank-you-calendar-50/',
'100-250': 'https://nilohealth.com/de/thank-you-calendar/',
'250-1000': 'https://nilohealth.com/de/thank-you-calendar/',
'10000+': 'https://nilohealth.com/de/thank-you-with-calendar-2/',
'1000-5000': 'https://nilohealth.com/de/thank-you-with-calendar/',
'5000-10000': 'https://nilohealth.com/de/thank-you-with-calendar-2/'
};
function testNumemployees(numemployees) {
redirectUrl = redirectUrls[numemployees] || redirectUrls[''];
console.log(`Redirect URL set to: ${redirectUrl} for numemployees: ${numemployees}`);
}
hbspt.forms.create({
region: "na1",
portalId: "8346198",
formId: "00aa77ce-d0b5-422c-887c-a59bcb8b2947",
inlineMessage: 'Thank you!',
onFormReady: function($form) {
const formId = '00aa77ce-d0b5-422c-887c-a59bcb8b2947';
const numemployeesFieldElement = document.querySelector(`#numemployees-${formId}`);
if (!numemployeesFieldElement) {
console.error("Number of employees field not found.");
return;
}
testNumemployees(numemployeesFieldElement.value);
numemployeesFieldElement.addEventListener("change", function() {
testNumemployees(numemployeesFieldElement.value);
});
setUTMFormData("utm_source");
setUTMFormData("utm_medium");
setUTMFormData("utm_campaign");
setUTMFormData("utm_content");
setUTMFormData("utm_term");
setHiddenFormData("acid", getCookie("_ga"));
let submitButton = document.querySelector(`#hsForm_${formId} input[type="submit"], #hsForm_${formId} button`);
if (submitButton) {
submitButton.id = "cta-contact-de";
console.log("Submit button ID set:", submitButton.id);
} else {
console.error("Submit button not found!");
}
},
onFormSubmitted: function() {
console.log("Form submitted. Redirecting to:", redirectUrl);
if (redirectUrl) {
window.location.href = redirectUrl;
} else {
console.error("Redirect URL is undefined. Check your configuration.");
}
}
});