Form Prefill Functionality is not working in embed form | Community
Skip to main content
Sep 25, 2017 12:39 PM UTC
Solved

Form Prefill Functionality is not working in embed form

Hi

I have used the embed code of the form in the marketo LP and to prefill the form I am using rest API's of the marketo but I am getting the error " No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin is therefore not allowed access.".

Please let me know if anyone has solved this type of problem.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
Sep 25, 2017 3:05 PM UTC

I have used the embed code of the form in the marketo LP and to prefill the form I am using rest API's of the marketo but I am getting the error " No 'Access-Control-Allow-Origin' header is present on the requested resource.

Never, ever, ever even think about exposing the REST API directly from a webpage.  The security and reliability consequences are absurd.  Honestly, you should shut down your web presence before considering this.

In your case, there's no need to consider this.  If it's a Marketo LP using the embed code instead of a named Form element (not advisable, but you can do it if you insist) then you can for the most part fill the form using tokens:

MktoForms2.whenReady(function(form){

  form.setValues({

    LastName : "{{Lead.Last Name}}"

  });

});

Also be aware that multiple Marketo forms with the same ID on the same page have subtle problems (yes, even if one of them is set to display: none;). You can check some of my posts here for pointers.

26 replies

Nov 3, 2017 6:11 PM UTC

Checkout this script: MarTech/Form-Prefill

It prefills embedded Marketo forms using AJAX request to a native Marketo landing page, so you don't need to code anything or use the REST API to query the lead's data.

I'd love to hear your feedback!

Translate
SanfordWhiteman
Level 10
Nov 3, 2017 6:35 PM UTC

Marketo changed their CORS policy?

Translate
Sep 29, 2017 5:55 AM UTC

I would apreciate if form-prefill would work in external embedded forms.

Or is there another solution to use the prefill function in external pages?

Translate
SanfordWhiteman
Level 10
Sep 29, 2017 6:20 AM UTC

There's a method I've used w/my clients for the last couple of years and I'm getting tired of teasing it -- before EOY I'm going to open the source.

Translate
Sep 29, 2017 6:33 AM UTC

Hi Sandford, I would be happy if you would share your code here :-) Best Johanna

Translate
SanfordWhiteman
Level 10
Sep 25, 2017 6:14 PM UTC

You mean coercing "1" and "" to true and false?

Translate
Sep 25, 2017 6:26 PM UTC

yes.

Translate
SanfordWhiteman
Level 10
Sep 25, 2017 8:00 PM UTC

{

  myBooleanField: !!+"{{Lead.Boolean Field}}"

}

Translate
SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
Sep 25, 2017 3:05 PM UTC

I have used the embed code of the form in the marketo LP and to prefill the form I am using rest API's of the marketo but I am getting the error " No 'Access-Control-Allow-Origin' header is present on the requested resource.

Never, ever, ever even think about exposing the REST API directly from a webpage.  The security and reliability consequences are absurd.  Honestly, you should shut down your web presence before considering this.

In your case, there's no need to consider this.  If it's a Marketo LP using the embed code instead of a named Form element (not advisable, but you can do it if you insist) then you can for the most part fill the form using tokens:

MktoForms2.whenReady(function(form){

  form.setValues({

    LastName : "{{Lead.Last Name}}"

  });

});

Also be aware that multiple Marketo forms with the same ID on the same page have subtle problems (yes, even if one of them is set to display: none;). You can check some of my posts here for pointers.

Translate
Sep 25, 2017 5:21 PM UTC

Thanks, Sanford.

Could you please help me to assign the checkbox values also.

Translate
Sep 25, 2017 1:34 PM UTC

Just to clarify. Are you using the embed code in a Marketo LP or in a Web Page? You don't need an embed code to display a Marketo form in a Marketo LP, just add a form: Landing Page with a Form - Marketo Docs - Product Docs

Then you select the option to prefill the form.

Translate
Sep 25, 2017 1:42 PM UTC

I am using the embed code in marketo LP because I am working on some functionality which requires 2 same form with a different layout in desktop and mobile view which is not possible in adding the form functionality.

Translate
Josh_Hill13
Level 10
Sep 25, 2017 2:04 PM UTC

Please send us a link or clearer explanation.

  • Marketo hosted Landing Page must use the native Form
  • Embed code is for external sites. This code does not support all functions like prefill.
  • Custom Form - you can write code to do special things, but that's up to you.
  • CSS Mods - if you are having trouble with responsive, then you need CSS and other mods. You shouldn't need to re-code the entire Form.
Translate