<script>
var formIds = [1014],
podId = '//app-XXX.marketo.com',
munchkinId = 'XXX-XXX-XXX';
/* no need to touch anything below this line */
var MKTOFORM_ID_PREFIX = 'mktoForm_',
MKTOFORM_ID_ATTRNAME = 'data-formId';
formIds.forEach(function(formId) {
var loadForm = MktoForms2.loadForm.bind(MktoForms2, podId, munchkinId, formId),
formEls = [].slice.call(document.querySelectorAll('[' + MKTOFORM_ID_ATTRNAME + '="' + formId + '"]'));
(function loadFormCb(formEls) {
var formEl = formEls.shift();
formEl.id = MKTOFORM_ID_PREFIX + formId;
loadForm(function(form) {
formEl.id = '';
formEls.length && loadFormCb(formEls);
});
})(formEls);
return false;
});
</script>
By using the above code, on submit how to display different thank you messages for both the forms.
If the form elements look like:
<form data-formid="2387" data-formname="Top Form"></form>
<form data-formid="2387" data-formname="Bottom Form"></form>
Then you can switch based on the ID and any distinguishing attributes:
MktoForms2.whenReady(function(mktoForm){
var formId = mktoForm.getId(),
formEl = mktoForm.getFormElem()[0],
formName = formEl.getAttribute("data-formname");
mktoForm.onSuccess(function(submittedValues,thankYouURL){
if (formId == 2387 && formName == "Top Form") {
// do whatever
}
if (formId == 2387 && formName == "Bottom Form") {
// do whatever else
}
});
});