Insert text after hiding embedded form on submit | Community
Skip to main content
December 3, 2014
Solved

Insert text after hiding embedded form on submit

  • December 3, 2014
  • 3 replies
  • 2886 views
I would like to use an embedded form to capture subscribers to my blog.  When I embed the form, I plan to use the developer code to hide the form upon successful submission.

What I'd like to do is add some text to appear in place of the form - e.g. "Thank you for subscribing".  Does anyone know how I can do that?

The code to hide the embedded form is as follows:

<script>MktoForms2.loadForm("//my.marketoinstance.com", "my account", form number,  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; 
      });
});</script>


Thanks in advance for your help!
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by
What you can do is to have a the message you want after submiting the form to be in a hidden div right after your form. 

Let's say your message is in:

<div id="msg" style="display:none;"> Thank you for subscribing </div>

Then in your code right after   form.getFormElem().hide();

$('#msg').show();


 

3 replies

Accepted solution
December 4, 2014
What you can do is to have a the message you want after submiting the form to be in a hidden div right after your form. 

Let's say your message is in:

<div id="msg" style="display:none;"> Thank you for subscribing </div>

Then in your code right after   form.getFormElem().hide();

$('#msg').show();


 
December 4, 2014
Thanks!  That worked great!
 
July 16, 2015

Hi, I would like to so a similar thing but the code provided is not working for me. Maybe I am writing it wrong? Any feedback would be highly appreciated.

<script src="//app-ab06.marketo.com/js/forms2/js/forms2.min.js"></script>

<form id="mktoForm_1133"></form>

<div id="msg" style="display:none;"> Thank you</div>

<script>MktoForms2.loadForm("//app-ab06.marketo.com", "790-LFQ-371", 1133,function(form) {

       // Add an onSuccess handler

    // Add an onSuccess handler

    form.onSuccess(function(values, followUpUrl) {

        // Get the form's jQuery element and hide it

       

     form.getFormElem().hide();

    

$('#msg').show();

return false;

});

});

</script>

SanfordWhiteman
Level 10
July 16, 2015

There are many recipes to accomplish this kind of thing -- search old Comm'ty posts for my demos.

Here's one: MktoForms2 :: Replace Form with TY Text