Capture form that has no name for all its elements even the form itself

gerard_reyes Posted by: Gerard Reyes Date Posted: May 27, 2024
Back to Case Studies

Issue

The form and all its elements have no name; therefore, the lead cannot be captured.

Solution

I created a faux form that loops through all the inputs and assigns it a custom name to be used for lead capture.

// Clone the form to leave the original form untouched
var originalForm = this.closest('form');
var formClone = originalForm.cloneNode(true);
var clonedFormId = 'mcfx_custom_id_contact_us'; // Fill this out please.

formClone.removeAttribute('id');
formClone.id = clonedFormId; // This removes the original ID and add a new ID that you can use as selector for Form
formClone.removeAttribute('class'); // Remove all classes from the cloned form
formClone.removeAttribute('name'); // Remove all classes from the cloned form

var formElements = formClone.querySelectorAll('input, select, textarea');

formElements.forEach(function(element, index) {
     if (!element.getAttribute('name')) {
         element.setAttribute('name', 'fx-id-' + index);
     }
});

// Now, capture the cloned form
mcfx('capture', formClone);
console.log('MCFX capture success');

Achievement

The lead was captured.

Snippet/Screenshot/Link

Ticket: Link