function confirmContactUS() {
const form = document.getElementById('contactus');
if (form) {
var formElements = form.querySelectorAll('input, select');
};
const errorText = document.getElementById('errorText');
const errorTextLine = document.getElementById('errorText');
if (form) {
const required = form.checkValidity();
if (!required) {
let error = "";
formElements.forEach(function (element) {
if (element.required && element.value === '' && element.disabled == false) {
error += '
' + element.name + " " + "is verplicht." + ''
}
});
if (errorText && error !== "") {
errorTextLine.innerHTML = "";
errorText.style.display = "block";
errorTextLine.innerHTML = '';
}
return false;
}
}
const emailValue = document.getElementById("email").value;
const companyId = document.getElementById("companyName").value;
const initialValue = document.getElementById("initials").value;
const firstnameValue = document.getElementById("firstname").value;
const middlenameValue = document.getElementById("middlename").value;
const lastnameValue = document.getElementById("lastname").value;
const streetValue = document.getElementById("differentStreet").value;
const numberValue = document.getElementById("differentNumber").value;
const postalcodeValue = document.getElementById("differentZipCode").value;
const cityValue = document.getElementById("differentCity").value;
const countryValue = document.getElementById("differentAddressCountry").value;
$('#SpinnerModalContactUs').modal('show');
webapi.safeAjax({
type: "POST",
url: "/_api/contacts",
contentType: "application/json",
data: JSON.stringify({
"firstname": firstnameValue,
"middlename": middlenameValue,
"lastname": lastnameValue,
"msdyn_initials": initialValue,
"emailaddress1": emailValue,
"cgk_portalcompanyname": companyId,
"cgk_portalstreet": streetValue,
"cgk_portalline2": numberValue,
"cgk_portalzipcode": postalcodeValue,
"cgk_portalcity": cityValue,
"cgk_portalcountry": countryValue
}),
success: function (res, status, xhr) {
window.location.replace("/contact-us/succes/");
}
});
}