Get connected with our team
Thanks for your interest in our products and services. Let's collect some information so we can connect you with the right person.
';
let submitButton = $('form.mktoForm .mktoButtonWrap .mktoButton');
submitButton.prop("disabled", true);
submitButton.append(loadingHTML);
// Ocp-Apim-Subscription-Key: '***'.
var $ocpKey = drupalSettings.ul_marketo_validate_key;
var $ocpUrl = drupalSettings.ul_marketo_validate_url;
var $ocpEnv = drupalSettings.ul_marketo_validate_env;
if (submitCount > 1 || isResponseSuccess == true) {
isResponseHandled = true;
form.submittable(true);
if (paramsDebug.debug == 1) {
console.log("NO.10 submitCount > 1: form.submit() ");
}
submitButton.click();
}
else {
var email = form.vals().Email;
var phone = (form.vals().Phone) ? (form.vals().Phone) : '18472728800';
var country = (form.vals().Country) ? (form.vals().Country) : 'United States';
var countryCode = (phone == '18472728800') ? 'US' : getCountryCode(country);
var $emailMsg = drupalSettings.ul_marketo_validate.email;
var $phoneMsg = drupalSettings.ul_marketo_validate.phone;
if (paramsDebug.debug == 1) {
console.log("paramsDebug:");
console.log(paramsDebug);
}
sendingData = JSON.stringify({
'Input_Email': email,
'Input_Phone': phone,
'Input_ISO2_Country_Code': countryCode
});
if (paramsDebug.debug == 1) {
console.log('URL, debug missing button:');
console.log($ocpUrl);
console.log("Sending Data to API service (ajax):");
console.log(sendingData);
}
// API call for validate email/phone/country.
var sendDate = (new Date()).getTime();
var responseTimeMs = sendDate;
// Start a timer to handle a 3-second response timeout
setTimeout(function() {
if (!isResponseHandled) {
isResponseHandled = true;
// Handle the assumed "success" due to timeout here
if (paramsDebug.debug == 1) {
console.log('No response within timeout, proceeding with default validation success.');
}
$('#ValidMsgEmail').remove();
$('#ValidMsgPhone').remove();
// set form to be submittable here
$('#valSpinner').remove();
submitButton.prop("disabled", false);
// Setup status as Timeout instead of Unknown.
emailAddressStatus = "Timeout";
phoneNumberStatus = "Timeout";
phoneNumberValidated = "Timeout";
form.vals({
"emailAddressStatus": emailAddressStatus,
"phoneNumberStatus": phoneNumberStatus,
"phoneNumberValidated": phoneNumberValidated,
});
form.submittable(true);
isResponseSuccess = true;
if (paramsDebug.debug == 1) {
let receiveDate = (new Date()).getTime();
responseTimeMs = (receiveDate - sendDate) / 1000;
console.log("setTimeout: " + responseTimeMs + " seconds.");
}
submitButton.click();
}
}, paramsDebug.timeout * 1000); //END setTimeout
$.ajax({
url: $ocpUrl,
type: 'POST',
data: sendingData,
headers: {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': $ocpKey,
},
success: function (response) {
$('#valSpinner').remove();
submitButton.prop("disabled", false);
phoneNumberValidated = response.Validated_Phone_Number;
if (!isResponseHandled) {
isResponseHandled = true;
// **** Handle the validation response
if (paramsDebug.debug == 1) {
console.log("API Response Data: ");
console.log(response);
}
var emailCode = response.Email_Validation_Status_Number;
var phoneCode = response.Phone_Validation_Status_Number;
// Add values into two status fields.
if (emailValidCode.hasOwnProperty(emailCode)) {
emailAddressStatus = emailValidCode[emailCode];
}
else {
// API error code doesn't exist, set defaul.
emailAddressStatus = emailValidCode['300'];
}
if (phoneValidCode.hasOwnProperty(phoneCode)) {
phoneNumberStatus = phoneValidCode[phoneCode];
}
else {
// API error code doesn't exist, set defaul.
phoneNumberStatus = phoneValidCode['301'];
}
if (emailAddressStatus.indexOf("email_not") != -1) {
emailAddressStatus = 'Invalid';
}
else if(emailAddressStatus == 'valid') {
emailAddressStatus = 'Valid';
}
if (phoneNumberStatus.indexOf('invalid_') != -1) {
phoneNumberStatus = 'Invalid';
}
else if(phoneNumberStatus == 'valid') {
phoneNumberStatus = 'Valid';
}
if (paramsDebug.debug == 1) {
console.log('form.emailAddressStatus ' + emailAddressStatus);
console.log('form.phoneNumberStatus ' + phoneNumberStatus);
console.log('form.phoneNumberValidated ' + phoneNumberValidated);
}
if (validEmailCode.includes(emailCode) && validPhoneCode.includes(phoneCode)) {
// Remove the loading spinner.
$('#ValidMsgEmail').remove();
$('#ValidMsgPhone').remove();
$('#valSpinner').remove();
submitButton.prop("disabled", false);
if (paramsDebug.debug == 1) {
console.log("NO.1.1 VALID OK submitCount = " + submitCount);
}
isResponseSuccess = true;
form.vals({
"emailAddressStatus": emailAddressStatus,
"phoneNumberStatus": phoneNumberStatus,
"phoneNumberValidated": phoneNumberValidated,
});
form.submittable(true);
submitButton.click();
}
// API valid code is not "valid".
else {
form.submittable(false);
if (paramsDebug.debug == 1) {
console.log("NO.1.2 Submittable false : count= " + submitCount + " validateOrigin " + validateOrigin + " isResponseSuccess " + isResponseSuccess );
}
// Set the invalid message in language translation.
var msgEmailStatus = "";
if (!validEmailCode.includes(emailCode)) {
if (emailCode == '300' || emailCode == '400') {
msgEmailStatus = $emailMsg.email_not_valid;
}
else if (emailCode == '310' || emailCode == '500' ) {
msgEmailStatus = $emailMsg.email_not_accept;
}
else {
msgEmailStatus = "Unknown";
}
if (paramsDebug.debug == 1) {
console.log("NOT validEmailCode: " + msgEmailStatus);
}
errEmail = '