//
//External Script
//
hsPortalId = '22621859';
hsformId = "8471c750-c633-488f-9ff6-5c2c008f1916";
//
layout = 2;
exclude_free_emails = true;
title = "LS-SA Intrado.com Form";
//
//Fields
//
display_fields = ["firstname","lastname","company","jobtitle","phone","state","country","comments","email"]
required_fields = ["firstname","lastname","company","jobtitle","phone","state","country","comments","email"]
//
//Submit Button Text
submit_text = 'Submit';
//
//Attribution
//
lead_source = 'Website';
lead_source_detail = 'Contact Us';
lead_source_other = 'Intrado.com Syn-Apps Main Form';
cid = '';
//
nurture_track = '';
//
//Thank you functions
//
thankyouInline = true;
thankyouInlineMessage = 'We will contact your shortly';
//If ThankYouInline false place redirect link here:
redirectLink = 'http://www.intrado.com';
//Download Button
thankyoubutton = false;
thankyouButtonLink = 'http://www.intrado.com'
thankyouButtonText = 'Download Now!'
//Autoresponder
emailID = "";
//Placeholder Text
placeholder_text = true;
//Multiple Form Handler
jQuery(document).ready(function() {
var modalID = jQuery('[class*="eloquaform"]:first').attr("form-modal-id")
jQuery('[class*="eloquaform"]').each(function() {
jQuery(this).attr("form-modal-id",modalID);
});
});
//Segment
var segment = 'LS';
//CID
if (typeof getQueryStringParamValueIF('cid') != 'undefined' && getQueryStringParamValueIF('cid') != '') {
jQuery('[name="cid"]').val(getQueryStringParamValueIF('cid')).change();
var cid = getQueryStringParamValueIF('cid');
}
window.jQuery = window.jQuery || (() => ({
// these are all methods required by HubSpot
change: () => {},
trigger: () => {},
}));
(function ($) {
//ThankYouButton
if (thankyoubutton == true) {
var dlbutton = '
';
} else {var dlbutton = '';}
if (thankyouInline == true) {
var tyinlinemsg = ' 
Thank You for Your Submission
'+thankyouInlineMessage+'
'+dlbutton+'';
}
else { var tyinlinemsg = '
' }
hbspt.forms.create({
portalId: hsPortalId,
formId: hsformId,
sfdcCampaignId: cid,
css: "",
inlineMessage: tyinlinemsg,
onFormReady: function($form) {
$('[name="lead_source_most_recent"]').val(lead_source).change();
$('[name="lead_source_detail_most_recent"]').val(lead_source_detail).change();
$('[name="lead_source_other_most_recent"]').val(lead_source_other).change();
$('[name="cid"]').val(cid).change();
$('[name="eid"]').val(emailID).change();
////Add GDPR To Display Fields Array
$(".legal-consent-container").appendTo('.hs_submit');
$(".legal-consent-container .hs-richtext p").unwrap();
//Display Fields Hide
$form.find('.hs-input').closest(".field").hide();
$.each( display_fields, function( i, val ) {
$form.find('.hs-input[name='+val+']').closest(".field").addClass('display_field');
});
console.log(display_fields);
console.log(required_fields);
function webToLead() {
if(jQuery('.hbspt-form form').valid()){
console.log('valid');
var form = document.createElement("form");
form.method = "POST";
form.action = "https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8";
// Your org ID
var elementOID = document.createElement("input");
elementOID.name="oid";
elementOID.value='00D2E000000oJo9';
elementOID.setAttribute("type", "hidden");
form.appendChild(elementOID);
// SFDC redirects to retURL in the response to the form post
var elementRetURL = document.createElement("input");
elementRetURL.name="retURL";
elementRetURL.value='https://www.intrado.com/en/revolutionforschools';
elementRetURL.setAttribute("type", "hidden");
form.appendChild(elementRetURL);
// These fields are optional debugging elements. Uncomment
// these lines if you wish to test in debug mode.
//var elementDebug = document.createElement("input");
//elementDebug.name="debug";
//elementDebug.value='1';
//elementDebug.setAttribute("type", "hidden");
//form.appendChild(elementDebug);
//var elementDebugEmail = document.createElement("input");
//elementDebugEmail.name="debugEmail";
// elementDebugEmail.value='kalthoff@colorado.edu';
//elementDebugEmail.setAttribute("type", "hidden");
//form.appendChild(elementDebugEmail);
// Whatever params you want;
// generate a form from Customize | Leads | Web-to-Lead to figure out more
var elementFirstName = document.createElement("input");
elementFirstName.name="first_name";
elementFirstName.value=$("input[name='firstname']").val();
elementFirstName.setAttribute("type", "hidden");
form.appendChild(elementFirstName);
var elementLastName = document.createElement("input");
elementLastName.name="last_name";
elementLastName.value=$("input[name='lastname']").val();
elementLastName.setAttribute("type", "hidden");
form.appendChild(elementLastName);
var elementEmail = document.createElement("input");
elementEmail.name="email";
elementEmail.value=$("input[name='email']").val();
elementEmail.setAttribute("type", "hidden");
form.appendChild(elementEmail);
var elementTitle = document.createElement("input");
elementTitle.name="title";
elementTitle.value=$("input[name='jobtitle']").val();
elementTitle.setAttribute("type", "hidden");
form.appendChild(elementTitle);
var elementCompany = document.createElement("input");
elementCompany.name="company";
elementCompany.value=$("input[name='company']").val();
elementCompany.setAttribute("type", "hidden");
form.appendChild(elementCompany);
var elementCompany = document.createElement("input");
elementCompany.name="company";
elementCompany.value=$("input[name='company']").val();
elementCompany.setAttribute("type", "hidden");
form.appendChild(elementCompany);
var elementPhone = document.createElement("input");
elementPhone.name="phone";
elementPhone.value=$("input[name='phone']").val();
elementPhone.setAttribute("type", "hidden");
form.appendChild(elementPhone);
var elementComments = document.createElement("input");
elementComments.name="description";
elementComments.value=$("textarea[name='comments']").val();
elementComments.setAttribute("type", "hidden");
form.appendChild(elementComments);
var elementSource = document.createElement("input");
elementSource.name="lead_source";
elementSource.value=$("input[name='ls_sfs_lead_source_most_recent']").val();
elementSource.setAttribute("type", "hidden");
form.appendChild(elementSource);
$form.submit();
document.body.appendChild(form);
setTimeout(function(){
form.submit();
}, 2000);
}
else {
console.log('invalid');
}
}
// Remove Hubspot Default form Submit Action to use jQuery validation
$form.find("input[type=submit]").on("click", function(e) {
if (typeof getCookie !== 'undefined' && getCookie != '') {$form.find("[name='ruid']").val(getCookie("ruid"));}
$form.find('.error').appendTo("hs-form-required");
webToLead();
});
//Free Emails Disallow Function
$.validator.addMethod('nofreeemail', function (value) {
return /^([\w-.]+@(?!icloud\.com)(?!protonmail\.ch)(?!protonmail\.com)(?!aol\.com)(?!outlook\.com)(?!gmail\.com)(?!gmail\.de)(?!yahoo\.com)(?!live\.com)(?!hotmail\.com)(?!mail\.ru)(?!yandex\.ru)(?!mail\.com)([\w-]+.)+[\w-]{2,4})?$/.test(value);
}, 'Free email addresses not allowed.');
$.validator.messages.required = 'Required';
// Form Validation of Required Fields
$form.validate({
rules: {
email: {
nofreeemail :exclude_free_emails ==true
}
},
messages: {
email: {
nofreeemail: "Please use a corporate email address."
}
}
});
$.fn.required = function() {
$.each(required_fields, function(i, val) {
$form.find('.hs-input[name="'+val+'"]').rules("add", { required: true });
});
}
$.fn.required();
//Placeholder Text
if (placeholder_text === undefined || placeholder_text == false) {
$.fn.placeholder = function() {
var placeholder_text = false;
//Font Height
if (layout == 2) {
$(document).ready(function() {
$form.find('.display_field label span').each(function() {
var elementHeight = $(this).height();
if (elementHeight > 27) {
$(this).css('font-size', '16px');
}
});
});
}
//Required Caret
if (required_fields.length > 1) {
$('.hs-form-required').remove();
$.each(required_fields, function(i, val) {
$form.find('.hs-input[name="' + val + '"]').closest(".field").prepend('*');
$form.find('.placeholder_required').css('margin-top', '5px');
});
}
}
} else if (placeholder_text == true) {
$.fn.placeholder = function() {
$form.find(":input").not('input[type=checkbox], input[type=radio]').each(function(index, elem) {
var eId = $(elem).attr("id");
var label = null;
$form.find('.hs-form-required').remove();
if (eId && (label = $(elem).parents().find("label[for=" + eId + "] span")).length == 1) {
$form.find(elem).attr("placeholder", $(label).html());
$form.find(label).not(".checkbox-aligned").remove();
}
});
//Required Caret
if (required_fields.length > 1) {
$.each(required_fields, function(i, val) {
console.log(val)
$form.find('.hs-input[name="' + val + '"]').closest(".field").prepend('*');
});
}
}
}
$.fn.placeholder();
//Layout Sort Functions
if (layout == 1) {
$form.find('input[type=submit]').css('width', '100%');
}
//Progressive Sort
$.fn.progressiveSort = function() {
$form.find(".hs-subscribe").nextAll('.smart-field').addClass('progressive');
$form.find(".progressive").insertBefore('.hs-subscribe');
}
//Submit Button Function
$.fn.submitbutton = function() {
setInterval(function() {
$(".hs-form input[type=submit]").val(submit_text);
}, );
}
$.fn.submitbutton();
//Layout 2 Sort
$.fn.layout2Sort = function() {
n = 0;
$form.find(":input").each(function() {
if ($(this).attr('type') != 'hidden' || $(this).prev('input').length ) {
$form.find(this).closest('.hs-form-field').addClass("line").removeClass("fullwidthrow row-odd row-even").removeAttr('row');
if ($(this).is("textarea") || $(this).is(":submit") || $(this).is(":checkbox") || $(this).is(":radio")) {
$(this).closest('.hs-form-field').addClass('fullwidthrow').css("width", "100%").removeClass('line');
}
}
});
$form.find(".line").each(function() {
if ($(this).prev('div').hasClass('fullwidthrow')) {
n = 0
}
$(this).closest('.hs-form-field').attr('row', n);
n++;
if (n == 2) {
n = 0
}
});
//Placeholder Cleanup
$form.find(".line").each(function() {
if ($(this).attr('row') == 0 && ( $(this).next().hasClass('hs_submit') || $(this).next('div').hasClass('fullwidthrow') || $(this).next('noscript').length || ($(this).closest(".hs-dependent-field").next('div').hasClass("fullwidthrow") && ($(this).next("div").length == 0)) )) {
$(this).closest('.hs-form-field').addClass('fullwidthrow').removeClass('line').removeAttr('row');
}
});
$form.find('.line[ row=' + 0 + ']').addClass('row-odd');
$form.find('.line[ row=' + 1 + ']').addClass('row-even');
}
//Conditional Fields
$(".hs-dependent-field .hs-input").change(function() {
if (layout == 2) {
setTimeout(() => {
$.fn.layout2Sort();
if ($("[name='state']").length) {
$.fn.statefilter();
}
$.fn.placeholder();
if (placeholder_text == 'true') {
$form.find(this).closest('.hs-dependent-field').find('label').not('input[type="checkbox"] label, input[type="radio"] label').hide();
}
$.fn.required();
},);
}
if (layout == 1) {
setTimeout(() => {
$form.find('.hs-form input[type=submit]').css('width','100%');
if ($("[name='state']").length) {
$.fn.statefilter();
}
$.fn.placeholder();
if (placeholder_text == 'true') {
$form.find(this).closest('.hs-dependent-field').find('label').not('input[type="checkbox"] label, input[type="radio"] label').hide();
}
$.fn.required();
},);
}
});
//Progressive Sort
$form.find(".hs-subscribe").nextAll('.smart-field').addClass('progressive');
$form.find(".progressive").insertBefore('.hs-subscribe');
//Display Fields Fade In
$form.fadeIn(400);
$.each(display_fields, function(i, val) {
$form.find('.hs-input[name=' + val + ']').closest(".field").fadeIn(400);
});
$form.find('.field').each(function() {
if ($(this).css('display') == 'none') {
$(this).removeClass('field hs-form-field').appendTo('form');
}
});
//STATE FILTER FUNCTIONS
//
//Page Load If Country Present
if ($(".display_field [name='country']").length) {
//Page Load State Field Country Logic
var provinceArray = ["Alberta", "Manitoba", "British Columbia", "New Brunswick", "Newfoundland and Labrador", "Nova Scotia", "Northwest Territories", "Nunavut", "Ontario", "Prince Edward Island", "Quebec", "Saskatchewan", "Yukon Territory"];
var optionValue = $("[name='state']").val();
//State Filter Function
$.fn.statefilter = function() {
$("[name='state']").children('option').show();
$('[name="state"] option').filter(function() {
if ("United States" == $("[name='country'] option:selected").val()) {
return $.inArray($.trim($(this).val()), provinceArray) !== -1;
}
else if ("Canada" == $("[name='country'] option:selected").val()) {
return $.inArray($.trim($(this).val()), provinceArray) == -1;
}
}).hide();
}
}
//
//START OF COUNTRY/STATE FUNCTIONS
//
//Page Load IP Lookup
$.get("https://extreme-ip-lookup.com/json/", function(e) {
if (e.status == 'success') {
$("[name='country']").val(e.country);
if ($("[name='state']").length) {
$.fn.statefilter();
}
}
});
//Change Function Country
$("[name='country']").change(function() {
if ($("[name='state']").length) {
$.fn.statefilter();
}
});
//Page Load If US/CA Field Merge
if ("United States" == $("[name='country'] option:selected").val() || "Canada" == $("[name='country'] option:selected").val()) {
if ($("[name='state']").length) {
$.fn.statefilter();
}
}
if (layout == 2) {
$.fn.layout2Sort();
}
//Add Google Event on Form Submit
var GAeventLabel = title + ' Form Submission';
var id_lookupTable = {
'bd32dbaa-657e-4ed3-a3c6-97daf6a5ef6b': 'LS-SA',
};
window.addEventListener("message", function(event) {
if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmitted') {
console.log('submitted');
dataLayer.push({
'event': 'form-submission',
'formName': id_lookupTable[event.data.id],
'eventLabel': GAeventLabel
});
}
});
//Title Case and URL
function titleCase(t) {
for (var e = t.toLowerCase().split(" "), r = 0; r < e.length; r++) e[r] = e[r].charAt(0).toUpperCase() + e[r].substring(1);
return e.join(" ")
}
if (typeof url != 'undefined' && url != '') {
var parts = url.split("/"),
last_part = parts[parts.length - 2],
last_part = last_part.replace(/[^\w\s]/gi, ' '),
last_part = titleCase(last_part);
}
else {
url = window.location.host+window.location.pathname;
}
//Intrado.com UTM
$form.find('[name="utm_content"]').val(decodeURI(getQueryStringParamValueIF('utm_content')));
$form.find('[name="utm_source"]').val(decodeURI(getQueryStringParamValueIF('utm_source')));
$form.find('[name="utm_medium"]').val(decodeURI(getQueryStringParamValueIF('utm_medium')));
$form.find('[name="utm_campaign"]').val(decodeURI(getQueryStringParamValueIF('utm_campaign')));
$form.find('[name="utm_term"]').val(decodeURI(getQueryStringParamValueIF('utm_term')));
$form.find('[name="url"]').val(url);
$form.find('[name="referral"]').val(getQueryStringParamValueIF('referral'));
if (typeof getQueryStringParamValueIF('source_main') != 'undefined' && getQueryStringParamValueIF('source_main') != '') {
$form.find('[name="ls_edu_lead_source_most_recent"]').val(decodeURI(getQueryStringParamValueIF('source_main'))).change();
}
if (typeof getQueryStringParamValueIF('source_detail') != 'undefined' && getQueryStringParamValueIF('source_detail') != '') {
$form.find('[name="ls_edu_lead_source_detail_most_recent"]').val(decodeURI(getQueryStringParamValueIF('source_detail'))).change();
}
if (typeof getQueryStringParamValueIF('source_other') != 'undefined' && getQueryStringParamValueIF('source_other') != '') {
$form.find('[name="ls_edu_lead_source_other_most_recent"]').val(decodeURI(getQueryStringParamValueIF('source_other'))).change();
}
if (typeof getQueryStringParamValueIF('gclid') != 'undefined' && getQueryStringParamValueIF('gclid') != '') {
$form.find('[name="gclid"]').val(getQueryStringParamValueIF('gclid')).change();
$form.find('[name="ls_edu_lead_source_most_recent"]').val('PPC').change();
}
//End Form Functions
},
onFormSubmitted: function() {
if (thankyouInline == false) {
window.location = redirectLink;
}
}
});
})(jQuery);