SOLVED

Marketo form in Salesforce Partner Community

Go to solution
SanfordWhiteman
Level 10 - Community Moderator

Re: Marketo form in Salesforce Partner Community

You don't have to pass the HTTP Referer header (Fetch referrer), though it's harmless to do so.

Pass the data in the form field _mktoReferrer.

Also, are you polyfilling Fetch? And make sure you're encodeURIComponent-ing all those values, Fetch won't do it based just on the Content-Type.

Luis_Florez1
Level 1

Re: Marketo form in Salesforce Partner Community

I am getting a 400 response code.

Here is the updated code based on your recommendations:

let params = [
'formid=1131',
'formVid=1131',
'munchkinId=' + encodeURIComponent('XXXXXXX'),
'FirstName=' + encodeURIComponent(this.userRecord.data.fields.FirstName.value),
'LastName=' + encodeURIComponent(this.userRecord.data.fields.LastName.value),
'Email=' + encodeURIComponent(this.userRecord.data.fields.Email.value),
'_mktoReferrer=' + encodeURIComponent(document.location.href)
];
fetch('https://XXXXXX.marketo.com/index.php/leadCapture/save2',
{
method: 'POST',
body: params.join('&'),
headers:{
'content-type': 'application/x-www-form-urlencoded'
}
}).then(result => {
console.log('result from registration');
console.log(result);
});‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Thanks in advance for all your help.

SanfordWhiteman
Level 10 - Community Moderator

Re: Marketo form in Salesforce Partner Community

Come to think of it, Fetch can't be used for this  at all because it's a blocked CORS request. Use a standard form post. 

Luis_Florez1
Level 1

Re: Marketo form in Salesforce Partner Community

Thank a lot.

The JS code actually worked. The form I was using was deleted while I was testing and I didn't see the error message then, but it was actually returning an error message about the form.

Many many thanks for your help.

Mark_Wright
Level 2

Re: Marketo form in Salesforce Partner Community

I am wondering if it would be possible to build a custom lightning component or something like that? Or a visualforce page?

SanfordWhiteman
Level 10 - Community Moderator

Re: Marketo form in Salesforce Partner Community

Possible? Yes. Has anyone proven it with fully working code?  Don't think so.

Mark_Wright
Level 2

Re: Marketo form in Salesforce Partner Community

Yeah I did it on a test community we have and it seemed to work ok, we havent put it on the live site yet though