APIs & Integrations

spf
Colaborador

localStorage conflicting with HubSpot form

resolver

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 Me gusta
1 Soluciones aceptada
spf
Solución
Colaborador

localStorage conflicting with HubSpot form

resolver

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:

Ver la solución en mensaje original publicado

2 Respuestas 2
IsaacTakushi
HubSpot Employee
HubSpot Employee

localStorage conflicting with HubSpot form

resolver

Welcome, @seanfilidis!

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

Isaac Takushi

Associate Certification Manager
0 Me gusta
spf
Solución
Colaborador

localStorage conflicting with HubSpot form

resolver

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: