Capturing Data from Squarespace Forms with Missing Input Names

Posted by: Julie Medrano Date Posted: October 22, 2025
Back to Case Studies

Issue

The client is using the Squarespace CMS and had difficulty tracking form submissions because Squarespace forms frequently lack name attributes on input fields, including the email field. This made it challenging to capture form submissions in LeadManagerFX.

Solution

To address this, we created a custom JavaScript script, with the help of TeamAI, to dynamically capture form data. The script creates a virtual form, adding name attributes to unnamed input fields as needed. A Mutation Observer ensures that even forms loaded after the initial page load are detected and processed. We found that without the Mutation Observer, some form submissions were not captured. This approach allows for accurate tracking of form submissions without directly modifying the Squarespace platform.

Achievement

Form submissions are captured in LeadManagerFX.

Snippet/Screenshot/Link

<script>
document.addEventListener('DOMContentLoaded', function() {
console.log('DOM fully loaded and parsed');
// Function to observe the DOM for the form
function observeForForm() {
const observer = new MutationObserver(function(mutations) {
// Select the form (adjust the selector if needed)
var fxform = document.querySelector('form.react-form-contents');
console.log('form found by MutationObserver: ' + fxform);
if (fxform) {
observer.disconnect(); // Stop observing
// Select the submit button within the form (update the selector)
const submitButton = fxform.querySelector('button[class*="form-submit-button"]');
console.log('button found' + ' ' + submitButton);
if (submitButton) {
submitButton.addEventListener('click', function(event) {
event.preventDefault(); // Prevent default form submission
console.log('submit button clicked');
// Create a new virtual form element
const virtualForm = document.createElement('form');
virtualForm.setAttribute('id', 'fx-contactus'); // Give it a fixed ID
// Capture the form data manually and add it to the virtual form
const elements = fxform.querySelectorAll('input, textarea, select');
let customIdCounter = 1;
for (let i = 0; i < elements.length; i++) {
const element = elements[i];
const fieldName = element.name || element.id || `fx-${i}`;
const hiddenInput = document.createElement('input');
hiddenInput.type = 'hidden';
hiddenInput.name = fieldName;
hiddenInput.value = element.value;
virtualForm.appendChild(hiddenInput);
console.log('Added hidden input to virtual form:', hiddenInput);
}
console.log('Virtual form created:', virtualForm);
// Call mcfx with the virtual form
mcfx('capture', virtualForm);
console.log('mcfx capture called');
});
}
}
});
// Start observing the document for changes
observer.observe(document.body, {
childList: true,
subtree: true
});
}
// Start observing for the form immediately after DOMContentLoaded
observeForForm();
});
</script>