' + opt_in_text;
}
var submit_btn_text = "";
if(submit_btn_text!=''){
baseFormElement.querySelector('.mktoButton').innerHTML = translateMarketoString(submit_btn_text);
}
var hideReqDemoField = "1";
if(!hideReqDemoField){
formObj.find('[for="demoRequest"]').parents('.mktoFormRow').css('display','none');
}
// auto fill form if user is logged in
var autofillForm = "";
// ajax to get VWO app logged in user data
if( autofillForm ){
$.ajax({
method: "GET",
url: "https://app.wingify.com/login",
xhrFields: {
withCredentials: true
}
})
.done(function( data ) {
autoFillFormData(data, formObj);
})
}
// if( typeof wp_visitor != "undefined") {
// form.vals({ "Email": ((wp_visitor.email != null) ? wp_visitor.email.replace(" ","+") : ""), "FirstName": wp_visitor.fn, "LastName": wp_visitor.ln, "Phone": wp_visitor.p, "Company": wp_visitor.c});
// }
//Add an onSuccess handler
var trackingData = {
"lt_utm_source__c": readCookie("_vwo_utm_source"),
"lt_utm_campaign__c":readCookie("_vwo_utm_campaign"),
"lt_utm_content__c":readCookie("_vwo_utm_content"),
"lt_utm_medium__c":readCookie("_vwo_utm_medium"),
"lt_utm_term__c":readCookie("_vwo_utm_term"),
"ads_source__c":readCookie("wgs_src"),
"ads_url__c":readCookie("wgs_url"),
"ads_user_id__c":readCookie("wgs_uid"),
//"ads_referer__c":readCookie("wgs_ref")
'Country': ((typeof VWOWebsiteUser.county_name != "undefined") ? VWOWebsiteUser.county_name : '') ,
'State': '' // Intentionaly sending empty state name
}
var timestamp = readCookie("wgs_time");
if( timestamp !== '' && timestamp !== null ) {
trackingData["ads_timestamp__c"] = marketoTimeConverter(parseInt(timestamp));
}
var hiddenFields = {"botDetection":"job title"};
var app_survey_option = readCookie('survey_answer');
if(readCookie('survey_form') != 1 && app_survey_option ){
var survey_option = {"1": "From a colleague/friend", "2": "Online advertisement", "3": "Found on search results",
"4": "Event", "5": "Other" };
if(app_survey_option && $.isNumeric(app_survey_option) ){
trackingData["Where_did_you_hear_about_us__c"] = survey_option[app_survey_option];
}else{
trackingData["Where_did_you_hear_about_us__c"] = survey_option[5];
trackingData["Specify_other_reason__c"] = app_survey_option;
}
}
form.vals(trackingData);
//set values to form fields
form.vals(hiddenFields);
var element = document.getElementById("botDetection");
if(element != null){
element.parentElement.parentNode.style.display = "none";
}
if((VWOWebsiteUser.continent && VWOWebsiteUser.continent != 'eu' && VWOWebsiteUser.continent != 'EU')
&&
!( (VWOWebsiteUser.state == "CA" || VWOWebsiteUser.state == "VA" || VWOWebsiteUser.state == "CO") && VWOWebsiteUser.country == "US") &&
!(VWOWebsiteUser.country == "IN") )
{
marketo_gdpr_consent(formObj);
}
//listen for the validate event
form.onValidate(function() {
// Get the values
var vals = form.vals();
var enable_workemail = "";
//Check your condition - Demo request is Yes and not a blocked email domian
if (((typeof vals.demoRequest != "undefined" && (vals.demoRequest == "yes" || vals.demoRequest == "Yes")) || enable_workemail) && vals.Email != "" && window.form.isEmailOfBlockedDomainList(vals.Email) ) {
// Prevent form submission
form.submittable(false);
// Show error message, pointed at Email element
var emailElem = formObj.find("input[type='email']");
emailElem.addClass('mkt-custom-invalid');
form.showErrorMessage("Please use your business email.", emailElem);
}
else {
// Enable submission for those who met the criteria
var emailElem = formObj.find("input[type='email']");
emailElem.removeClass('mkt-custom-invalid');
form.submittable(true);
}
});
form.onSubmit(function(){
var button_text = formObj.find('button[type="submit"]').text();
var formValues = form.getValues();
//update form button text to button attribute
formObj.find('button[type="submit"]').attr('data-button-text', button_text)
//if create cookie true
//set cookie on survey form submission
if(readCookie('survey_form') != 1 && readCookie('survey_answer') != "" ){
createCookie('survey_form', 1, 0);
}else {
}
});
form.changeButtonText = function(btnTxt) {
if (btnTxt == undefined || btnTxt == "" ) {
btnTxt = formObj.find('button[type="submit"]').data("button-text");
}
formObj.find('button[type="submit"]').text(btnTxt).removeAttr("disabled");
}
form.showCommonError = function(errorMsg) {
if (errorMsg == undefined || errorMsg == "") {
errorMsg = translateMarketoString("There is some technical error. Please try after some time or contact us at") + "
support@vwo.com";
}
formObj.find('.technical-error').remove();
formObj.append("
" + errorMsg + "");
}
form.onSuccess(function(values, followUpUrl) {
var require_survey_form = "1";
var dataLayer = window.dataLayer || [];
dataLayer.push({'event': 'marketo-content-form-success'});
dataLayer.push({
"event": "form-submit",
"form_type" : "partners"
});
submitDataInBigquery(formObj);
update_btn_count_in_cache(formObj);
//vwo form analysis
var form_id = "#mktoForm_" + "2184";
var formInstance = $( form_id );
window.VWO = window.VWO || [];
window.VWO.push(['nls.formAnalysis.markSuccess', formInstance, 1]);
//if redirect url is set
form.getFormElem().hide();
formObj.parent('.marketo-custom-form').find('.marketo_success_msg').removeAttr('style').css('display','block');
// if(require_survey_form && readCookie('survey_form') != 1 && readCookie('survey_answer') == '' ){
// $("#js_after_submit_survey_form").find('input[name="Email"]').val( $("input[type='email']", formObj).val() );
// formObj.parent('.marketo-custom-form').find('.marketo_success_msg').append( $("#js_after_submit_survey_form").css("display", "block") );
// }
//On success, hide js-form-header div HTML placed above form i.e form title or description
formObj.parents('.js-form-wrap').find('.js-form-header').hide();
// Js timer for form (Product Demo webinar)
modalFormOnSuccess(formObj);
return false;
});
function ajaxcallSetFormData( formObj ) {
var formData = formObj.serialize();
$.ajax({
url: '/wp-json/action/set-submitted-data',
type: 'POST',
data: { formData : formData },
});
}
function autoFillFormData(data, formObj) {
// var data = {name: '', email: '', phone: ''};
var nameArr, firstNameField, lastNameField, emailField, phoneField ;
var name = data.name;
if( name !=''){
nameArr = name.split(" ");
}
firstNameField = formObj.find('input[name="FirstName"]');
lastNameField = formObj.find('input[name="LastName"]');
emailField = formObj.find('input[name="Email"]');
phoneField = formObj.find('input[name="Phone"]');
// update field value and hide field
if( name !='' && typeof nameArr[0] != 'undefined'){
firstNameField.val(nameArr[0]);
hideFieldHtml(firstNameField);
}
// update field value and hide field
if( name !='' && typeof nameArr[1] != 'undefined'){
lastNameField.val(nameArr[1]);
hideFieldHtml(lastNameField);
}
// update field value only
if(data.email !='' ){
emailField.val(data.email);
}
// update field value and hide field
if(data.phone != ''){
phoneField.val(data.phone);
hideFieldHtml(phoneField);
}
$("body").delegate("form #Email", "change", function() {
$(this).parents("form").children().removeClass("marketo_hide_field");
});
// if user modfified autofilled email then show all form fields that are in hidden state and autofilled
/* DISABLE auto fill email focusout function
emailField.focusout(function() {
emailFieldValue = emailField.val();
if(data.email != '' && data.email != emailFieldValue)
{
emailField.parents('form').children().removeClass('marketo_hide_field');
}
});
*/
}
// hide form field
function hideFieldHtml(field){
var autofill_field_hide = "";
// hide field if it is equal to 1
if(autofill_field_hide){
field.parents('.mktoFormRow').addClass('marketo_hide_field');
}
}
function submitDataInBigquery( formObj ) {
var formData = formObj.serializeArray();
formData.push({
name: 'form_type',
value: 'partners'
});
formData.push({
name: 'security',
value: WP.NONCE
});
$.ajax({
url: '/wp-json/action/content-form',
type: 'POST',
data: formData,
beforeSend: function(xhr) {
xhr.setRequestHeader('X-WP-Nonce', WP.NONCE);
}
});
}
});
function modalFormOnSuccess(formObj){
var requestQuoteformParent = formObj.parents('.js-modal-box');
if(requestQuoteformParent.length > 0){
requestQuoteformParent.find('.contact_heading').hide();
}
var modalFormWrap = formObj.parents('.js-flex-modal');
if(modalFormWrap.length > 0){
modalFormWrap.find('.js-modal-header h3').hide();
modalFormWrap.find('.explore-btn-wrap').css('display','flex');
}
}
function marketo_gdpr_consent(formObj) {
return;
formObj.find('#implicitOptIn').parents('.mktoFormRow').css('display','none');
formObj.find('#implicitOptIn').prop('checked', true);
}
function update_btn_count_in_cache(formObj){
if (formObj.parent('.marketo-custom-form').hasClass('webinar_form')) {
$.ajax({
type: 'POST',
dataType: 'json',
url: siteVar.ajaxUrl,
data: {
action: 'webinar_form_counter',
id: siteVar.postId
},
success: function(response) {
if(response.status == 'success'){
// console.log(response.data.current);
}
}
});
}
}
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return '';
}
//timestamp converter
marketoTimeConverter = function (UNIX_timestamp) {
if( getLengthOfNumber(UNIX_timestamp) <= 10 ){
UNIX_timestamp = UNIX_timestamp * 1000
}
var a = new Date(UNIX_timestamp);
var year = a.getFullYear();
var month = a.getMonth()+1;
var date = a.getDate();
var hour = a.getHours();
var min = a.getMinutes();
var sec = a.getSeconds();
var time = year + '-' + month + '-' + date + 'T' + hour + ':' + min + ':' + sec + "z";
return time;
}
getLengthOfNumber = function(number){
return number.toString().length;
}
MktoForms2.whenRendered(function (form) {
if( typeof vwoVisitor != 'undefined' ) {
vwoVisitor.AddEvent("vpSessionLoaded", function(e) {
var implicitOptIn = "";
form.vals({ Email: vwoVisitor.data.email});
form.vals({ FirstName: vwoVisitor.data.fn});
form.vals({ LastName: vwoVisitor.data.ln});
form.vals({ Phone: vwoVisitor.data.phone});
form.vals({ Company: vwoVisitor.data.c});
form.vals({ MktoPersonNotes: vwoVisitor.data.message});
if (vwoVisitor.data.consent) {
var getConsent = vwoVisitor.data.consent;
if (getConsent.toLowerCase() === "yes") {
var implicitOptIn = "yes";
} else if (getConsent.toLowerCase() === "no") {
var implicitOptIn = "no";
}
}
form.vals({ implicitOptIn: implicitOptIn});
});
}
});
});