Solved
Hide lightbox form after submission
I have the form code below to embed a Marketo form as a lightbox.
<script src="//app-sj04.marketo.com/js/forms2/js/forms2.js"></script>
<form id="mktoForm_1244"></form>
<script>MktoForms2.loadForm("//app-sj04.marketo.com", "980-GBD-747", 1244, function (form){MktoForms2.lightbox(form).show();});</script>
However, the lightbox currently does not disappear when the form is submitted, it just reloads the page and pops up again. Marketo does provide a code for this (see below), but I don’t know how to combine the two pieces of code together so that it’s a lightbox AND it disappears after it is submitted. Can someone who knows JavaScript help me make this code work? Thanks!
1. MktoForms2.loadForm("//app-sjst.marketo.com", "980-GBD-747", 1244, function(form){
2. //Add an onSuccess handler
3. form.onSuccess(function(values, followUpUrl){
4. //get the form's jQuery element and hide it
5. form.getFormElem().hide();
6. //return false to prevent the submission handler from taking the lead to the follow up url.
7. return false;
8. });
9. });
<script src="//app-sj04.marketo.com/js/forms2/js/forms2.js"></script>
<form id="mktoForm_1244"></form>
<script>MktoForms2.loadForm("//app-sj04.marketo.com", "980-GBD-747", 1244, function (form){MktoForms2.lightbox(form).show();});</script>
However, the lightbox currently does not disappear when the form is submitted, it just reloads the page and pops up again. Marketo does provide a code for this (see below), but I don’t know how to combine the two pieces of code together so that it’s a lightbox AND it disappears after it is submitted. Can someone who knows JavaScript help me make this code work? Thanks!
1. MktoForms2.loadForm("//app-sjst.marketo.com", "980-GBD-747", 1244, function(form){
2. //Add an onSuccess handler
3. form.onSuccess(function(values, followUpUrl){
4. //get the form's jQuery element and hide it
5. form.getFormElem().hide();
6. //return false to prevent the submission handler from taking the lead to the follow up url.
7. return false;
8. });
9. });