Wussten Sie, dass wir eine deutschsprachige Community haben?

localStorage conflicting with HubSpot form

lösung
Highlighted
spf
Berater

I have a script on our "Create Account" page. It looks for a "referral-id" parameter in the URL and puts the value into a hidden field in the HubSpot form on the page. The script has worked as expected, until now.

I just updated the script to also store the value from the URL parameter in window.localStorage so that if a user leaves the page and comes back, it will retain the referral id.

The script works exactly as expected. The values are saved, and the hidden field is filled. However, the form no longer submits. Clicking submit merely does nothing. I get no console errors.

Does anyone have any ideas as to what's going on? Do HubSpot forms not like it when localStorage is used?

Here's the test page I'm working on: https://www.instantmagazine.com/create-account-test

var params;
var referredBy;
var hiddenField;

function fillHiddenField() {
	hiddenField = document.getElementsByName("referred_by");
	hiddenField[0].setAttribute("value",referredBy);
}

params = new URLSearchParams(document.location.search.substring(1));

if (params.has("referral-id")) {
	referredBy = params.get("referral-id");
	setTimeout(fillHiddenField, 1000);
	window.localStorage.setItem("storeReferrer", referredBy);

} else if (window.localStorage.storeReferrer) {
	referredBy = window.localStorage.getItem("storeReferrer");
	setTimeout(fillHiddenField, 1000);
}

Thanks guys.

Antworten
0 Like / Likes
Akzeptierte Lösung / Akzeptierte Lösungen

Akzeptierte Lösungen
spf
Berater

Solved my own problem.

Nothing was wrong with the script. The HubSpot property I was sending referral IDs to was a numeric field, and I was sending it IDs like "sean".

Changing the HubSpot property to a single line text field fixed everything. :rofl:

2 ANTWORTEN 2
spf
Berater

Solved my own problem.

Nothing was wrong with the script. The HubSpot property I was sending referral IDs to was a numeric field, and I was sending it IDs like "sean".

Changing the HubSpot property to a single line text field fixed everything. :rofl:

Moderator

Welcome, @seanfilidis!

I'm glad to hear you found the solution so quickly.

Isaac Takushi

HubSpot Developer Support
Antworten
0 Like / Likes