Hello,
I have an onSubmit function to submit leads into Marketo (had to do some customizing to load form data into Salesforce); I tried adding the onSuccess code to have the form stay on the page after form submission, hide the form and show a thank you div instead. However, it isn't working... the form stalls as it's submitting and does not submit anything (the submit button has become inactive).
Any thoughts? Thanks!
<script>MktoForms2.loadForm("************", "*****", ****,
function(form){
//Add the hidden fields for Calculator Quote URL
var currentURL = window.location.href;
form.addHiddenFields({"Calculator_Quote_URL__c":currentURL, "Company":"", "Lead_Created_Date__c":""});
//add an onSubmit handler
form.onSubmit(function(){
//Fill in the hidden company field for SF
$('[name="Company"]').val($("#LastName").val() + ', ' + $("#FirstName").val());
//Get the current date and insert into lead created date for SF
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10) {
dd='0'+dd
}
if(mm<10) {
mm='0'+mm
}
today = mm+'/'+dd+'/'+yyyy;
//document.write(today);
$('[name="Lead_Created_Date__c"]').val(today);
//get the form field values
varvals = form.getValues();
});
//Add an onSuccess handler
form.onSuccess(function(){
//get the form's jQuery element and hide it and show thank you
form.getFormElem().hide();
document.getElementById('confirmform').style.visibility = 'visible';
//return false to prevent the submission handler from taking the lead to the follow up url.
return false;
});
});
</script>