APIs & Integrations

spf
Mitwirkender/Mitwirkende

localStorage conflicting with HubSpot form

lösung

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.

0 Upvotes
1 Akzeptierte Lösung
spf
Lösung
Mitwirkender/Mitwirkende

localStorage conflicting with HubSpot form

lösung

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:

Lösung in ursprünglichem Beitrag anzeigen

2 Antworten
IsaacTakushi
HubSpot Employee
HubSpot Employee

localStorage conflicting with HubSpot form

lösung

Welcome, @seanfilidis!

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

Isaac Takushi

Associate Certification Manager
0 Upvotes
spf
Lösung
Mitwirkender/Mitwirkende

localStorage conflicting with HubSpot form

lösung

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: