Use Local Storage to capture lead

gerard_reyes Posted by: Gerard Reyes Date Posted: March 16, 2026
Back to Case Studies

Issue

The form is a multistep form. The inputs disappear when moving between pages. This results in a lead with incomplete inputs.

Solution

I added custom code to use Local Storage to temporarily store input values and use them later when a lead is captured.

<script>
(function() {
console.log(‘CH Capture Appointment Request’);

document.addEventListener(‘click’, function(event) {
//console.log(event.target);
if (event.target.textContent.trim() === ‘Next’) {
var form = document.querySelector(‘form’);
if (form) {
var formElements = form.querySelectorAll(‘input, select, textarea’);
var dataToStore = {};
var validNames = [‘firstName’, ‘lastName’, ‘phoneNumber’, ’email’];

for (var i = 0; i < formElements.length; i++) {
var element = formElements[i];
if (element.name && validNames.indexOf(element.name) !== -1) {
dataToStore[element.name] = element.value;
}
}

if (dataToStore.firstName && dataToStore.lastName && dataToStore.phoneNumber && dataToStore.email) {
localStorage.setItem(‘scheduler_form’, JSON.stringify(dataToStore));
console.log(localStorage.getItem(‘scheduler_form’));

var storedData = JSON.parse(localStorage.getItem(‘scheduler_form’));
var newForm = document.createElement(‘form’);
newForm.id = ‘rcfx-custom-id-scheduler-sign-up’;

for (var key in storedData) {
if (storedData.hasOwnProperty(key)) {
var hiddenInput = document.createElement(‘input’);
hiddenInput.type = ‘hidden’;
hiddenInput.name = ‘rcfx-custom-location-‘ + key;
hiddenInput.value = storedData[key];
newForm.appendChild(hiddenInput);
}
}

document.body.appendChild(newForm);

mcfx(‘capture’, newForm);
console.log(‘RCFX capture success’);
} else {
console.log(‘Missing required fields’);
}
}
}

document.addEventListener(‘mouseover’, function(event) {
//console.log(event.target);
if (event.target.textContent.trim() === ‘Book Appointment’) {
var locationSpan = Array.prototype.find.call(document.querySelectorAll(‘span’), function(span) {
return span.textContent.trim() === ‘LOCATION’;
});

if (locationSpan) {
var parentDiv = locationSpan.closest(‘div.ub-flx-drct_row’).nextElementSibling;
if (parentDiv) {
var targetSpan = parentDiv.querySelector(‘span’);
if (targetSpan) {
var locationText = targetSpan.textContent;
console.log(locationText);

var storedData = JSON.parse(localStorage.getItem(‘scheduler_form’));
var newForm = document.createElement(‘form’);
newForm.id = ‘rcfx-custom-id-scheduler-scheduled’;

for (var key in storedData) {
if (storedData.hasOwnProperty(key)) {
var hiddenInput = document.createElement(‘input’);
hiddenInput.type = ‘hidden’;
hiddenInput.name = ‘rcfx-custom-location-‘ + key;
hiddenInput.value = storedData[key];
newForm.appendChild(hiddenInput);
}
}

var locationInput = document.createElement(‘input’);
locationInput.type = ‘hidden’;
locationInput.name = ‘rcfx-custom-location’;
locationInput.value = locationText;
newForm.appendChild(locationInput);

document.body.appendChild(newForm);

mcfx(‘capture’, newForm);
console.log(‘RCFX capture success’);
}
}
}
}
});

});
})();
</script>

Achievement

The lead is captured.

Snippet/Screenshot/Link

Task: Link

Code: Screenshot