- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
localStorage conflicting with HubSpot form
SOLVE11-07-2018 03:37
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content