Re: On form submit, replace form with "thank you" message

Anonymous
Not applicable

Re: On form submit, replace form with "thank you" message

I had a similar issue. What I did was create a hidden DIV element with the "success message" I wanted to display somewhere on the page before or after the marketo SCRIPT and added a javascript line to make that DIV visible onSuccess.

<script src="//app-sjg.marketo.com/js/forms2/js/forms2.js"></script><form id="mktoForm_nnnn"></form><script>MktoForms2.loadForm("//app-sjg.marketo.com", "nnn-xxx-nnn", nnnnn, function(form){
  //Add an onSuccess handler
  form.onSuccess(function(values, followUpUrl){
    //get the form's jQuery element and hide it
    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>
<div id="confirmform" style="visibility:hidden;"><p><strong>Thank you. Check your email for details on your request.</strong.</p></div>
Anonymous
Not applicable

Re: On form submit, replace form with "thank you" message

Hi Derek - I realize this topic is old but hoping you are still subscribed to these posts. I found your previous reply helpful. Do you know how I could get the confirmation div to disappear after X amount of time (in my particular case I want to keep the form visible at all times and have the confirmation show up after submission for a few seconds, then disappear)? Thanks in advance!

 
Matt_Stone2
Level 9

Re: On form submit, replace form with "thank you" message

I would check out this thread for options on hiding the div after a few seconds: http://stackoverflow.com/questions/820951/hide-div-after-a-few-seconds -- you would just start out with showing it first, then exectue the script in that link to hide it after a few seconds.
Robb_Barrett
Marketo Employee

Re: On form submit, replace form with "thank you" message

Hi all -

Sorry for necroposting, but I've been using this functionality on my page but it's not prefilling the form. Is there a setting I need to add to get the pre-fill? The page has it enabled.

Robb Barrett
Matt_Stone2
Level 9

Re: On form submit, replace form with "thank you" message

If you're using the form javascript snippets, you won't be able to use prefill. It's a security restriction for transferring data off Marketo.

SanfordWhiteman
Level 10 - Community Moderator

Re: On form submit, replace form with "thank you" message

Forms 2.0 JS works fine on Marketo LPs. The prefill restriction is for non-Marketo LPs.

Robb_Barrett
Marketo Employee

Re: On form submit, replace form with "thank you" message

Looks like if the form is added directly in the page, the page puts in some JS to prefill with the appropriate fields.  If you use JS to call in the form, it doesn't automatically pull the LOF and prefill. The mktoPreFillFields is called automatically based on the form. 

Robb Barrett
SanfordWhiteman
Level 10 - Community Moderator

Re: On form submit, replace form with "thank you" message

Yes, you have to use an actual form, not JS that happens to call MktoForms2::loadForm.

Robb_Barrett
Marketo Employee

Re: On form submit, replace form with "thank you" message

I was able to get it to work with this bit of code.

form.vals({"Postal Code":"{{lead.Postal Code}}",

                         "Phone":"{{lead.Phone Number}}",

                         "Country":"{{lead.Country}}",

                         "First Name":"{{lead.First Name}}",

                         "Last Name":"{{lead.Last Name}}",

                         "Company":"{{company.Company Name}}",

                         "Email":"{{lead.Email Address}}",

                         "City":"{{lead.City}}",

                         "State":"{{lead.State}}",

                         "Address":"{{lead.Address}}"});

Robb Barrett
SanfordWhiteman
Level 10 - Community Moderator

Re: On form submit, replace form with "thank you" message

Sure, that's another way to do it if you're on a Marketo LP.  But I don't understand why you're using the JS instead of a true form widget.  Note you lose per-LP form fillout reporting this way.