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.
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.
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.
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.
I am wondering if it would be possible to build a custom lightning component or something like that? Or a visualforce page?
Possible? Yes. Has anyone proven it with fully working code? Don't think so.
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