Getting TypeError: Cannot read property 'requestContent' of undefined passing Form GuID via function
解決
I've been working on setting up a connection for the Hubspot Forms API that will handle all of our website forms by reading the pathname and then passing the appropriate GuID for the form to the API. That way I can have one function that handles form connections for all the different forms we have on our website.
I got it working, but I am running into an issue. Essentially, I tried to setup a function that reads the pathname and then assigns a form id based on the page path. Like this:
/**
SET THIS UP TO MATCH GUID TO PATHNAME
*/
function lookUpGuId() {
if (window.location.pathname = '/mobile-form-builder/') {
return '0138de5f-3570-4628-9966-a04755d0bd5b';
}
}
then in hubspotPost() I call that form the form ID like this:
function hubspotPost() {
var portalId = '6973045';
var formGuid = lookUpGuId();
var url = 'https://api.hsforms.com/submissions/v3/integration/submit/'+portalId+'/'+formGuid;
var hsData = getHubSpotData();
var data = JSON.stringify(hsData);
var xhr = new XMLHttpRequest();
But, when I set it up that way I get this error in the console:
It looks like it's passing the ID correctly, but I am getting "TypeError: Cannot read property 'requestContent' of undefined" in the debugger.
However, if I just put the GuID string into the formGuid variable, everything works as expected.