Forms 2.0 and Wordpress | Community
Skip to main content
January 28, 2014
Solved

Forms 2.0 and Wordpress

  • January 28, 2014
  • 7 replies
  • 2168 views
What is the best way to embed a form, using the form 2.0, into Wordpress.

When getting embed code, I see script that looks universal and I put this into the Footer.php file of the template. That means that the form support code will load on every page of the site.

src="//app-sji.marketo.com/js/forms2/js/forms2.js"

The trouble is on my pages themselves. The new form embed code requires an empty DOM element (easy enough) and then page-specific script to load the form from Marketo.

The issue is the Wordpress does not allow Script to be included in Page/Post content.

Suggestions? Specific page templates for any page I want a form on? Using a plugin to let script get put into a page/post?

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
I figured it out. Here's what I did and it was quite easy.
  1. Added a reference to src="//app-sji.marketo.com/js/forms2/js/forms2.js" in header.php of my template file. This was easier than loading it on each page. It loads as part of the site.
  2. Read the article here and did the following
    • Created a JavaScript file called loadMarketoForm.js and added to a /scripts folder on our site. It has the following code...
function loadMarketoForm(formId){

if (formId) {
    MktoForms2.loadForm("//app-sji.marketo.com", "our org id value", formId);
}

}
 
  • In my Page, it has something like below...
<form id="mktoForm_1017"></form>
<script type="text/javascript" src="/scripts/loadMarketoForm.js"></script>
<script type="text/javascript">
<!--
loadMarketoForm(1017);
//--></script>
 
  • As I create new Pages in Wordpress, if I want to incude a form, I copy the above code and I just change the form number (1017 above) to whatever is in the embed code for any new forms I create.
Works quite well.


7 replies

January 28, 2014
"The issue is the Wordpress does not allow Script to be included in Page/Post content." << Pretty sure this isn't true. 

http://codex.wordpress.org/Using_Javascript#JavaScript_in_Posts
Accepted solution
January 28, 2014
I figured it out. Here's what I did and it was quite easy.
  1. Added a reference to src="//app-sji.marketo.com/js/forms2/js/forms2.js" in header.php of my template file. This was easier than loading it on each page. It loads as part of the site.
  2. Read the article here and did the following
    • Created a JavaScript file called loadMarketoForm.js and added to a /scripts folder on our site. It has the following code...
function loadMarketoForm(formId){

if (formId) {
    MktoForms2.loadForm("//app-sji.marketo.com", "our org id value", formId);
}

}
 
  • In my Page, it has something like below...
<form id="mktoForm_1017"></form>
<script type="text/javascript" src="/scripts/loadMarketoForm.js"></script>
<script type="text/javascript">
<!--
loadMarketoForm(1017);
//--></script>
 
  • As I create new Pages in Wordpress, if I want to incude a form, I copy the above code and I just change the form number (1017 above) to whatever is in the embed code for any new forms I create.
Works quite well.


January 28, 2014
So, what I said? ;-)
January 28, 2014
Jason, yes, what you said, but I wanted to document the implementation rather than just a link to read more about how to do it. I figured that is more valuable to the community.
January 28, 2014
Thanks Scott :) Always love to see more WordPress stuff on here.
January 28, 2014
Sure thing. I wasn't trying to boost myself with the Best Answer selection either. I just thought the implementation of it should be marked. I honestly don't care about that stuff, but thought others might want to jump right to the answer.
April 18, 2014
Or if you want an even easier solution, you can use the Marketo-Wordpress integration on Launchpoint

This allows you to convert any Wordpress form into a Marketo form with pre-fill and progessive profiling. All it takes is a some shortcodes:

[mForm] ... your form .... [/mForm]


See it in action at the Marketo Health-checker. Do a health check, then reload the original page.