I currently have a hidden form which auto-submits upon page load using the following code:
<script src="//app-abXX.marketo.com/js/forms2/js/forms2.min.js"></script>
<form id="mktoForm_3023" style="display:none;"></form>
<script>
MktoForms2.loadForm("//app-abXX.marketo.com", "XX-XX-XX", 3023, function(form) {
// Add an onSuccess handler
form.onSuccess(function(values, followUpUrl) {
// Get the form's jQuery element and hide it
form.getFormElem().hide();
// Return false to prevent the submission handler from taking the lead to the follow up url
return false;
});
form.submit();
});
</script>
We use this form in conjunction with URL parameters to update fields on the fly for our website visitors based on their actions. Recently, we've started to notice that on one of our landing pages, due to this auto-submitting form, new records are being created for users that are already in our database causing a bit of a headache for our reporting since records are being duplicated.
Is there any way to stop the form above from auto-submitting if the email field is empty?
Solved! Go to Solution.
MktoForms2.loadForm("//app-abXX.marketo.com", "XX-XX-XX", 3023);
MktoForms2.whenReady(function(form){
let currentValues = form.getValues();
form.onSuccess(function(values, followUpUrl) {
form.getFormElem().hide();
return false;
});
if(currentValues.Email){
form.submit();
}
});
Of course you can do it using JS, but the easier way is to just make the Email field required. Marketo will not be able to submit the form if the Email field is req'd, even/especially when it's hidden.
Thanks for the speedy reply.
Right now, I have the email field set as a hidden field pulling in values via URL parameter. I don't believe I'd be able to do that if I set the field as an email field and as required. I don't believe I get the option to pre-fill the field with a URL parameter at that point.
Note: this form is embedded in a non-Marketo landing page.
MktoForms2.loadForm("//app-abXX.marketo.com", "XX-XX-XX", 3023);
MktoForms2.whenReady(function(form){
let currentValues = form.getValues();
form.onSuccess(function(values, followUpUrl) {
form.getFormElem().hide();
return false;
});
if(currentValues.Email){
form.submit();
}
});