Blank forms is being captured and prevents blank forms settings is not working

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

Issue

The client receives a blank form even if the form is not yet fully filled up. The LeadManagerFX’s prevents blank forms setting is also not blocking the blank form or lead.

Solution

I created a script in Google Tag Manager to block the submission of a form to MCFX if the email value is not yet filled out.

 

jQuery('input[type="submit"]').on('click', function(event) {
     // Clone the form to leave the original form untouched
     var $originalForm = jQuery(this).closest('form');
     var $formClone = $originalForm.clone();
     var clonedFormId = 'mcfx_custom_id_distributor_interest_form'; // Fill this out please.

     var $yourEmailInput = $formClone.find('input[name="your-email"]');
     if ($yourEmailInput.val() === '') {
         console.log('The input with name "your-email" is empty.');
     } else {
         $formClone.removeAttr('id').attr('id', clonedFormId); // This removes the original ID and add a new ID that you can use as selector for Form
         $formClone.removeAttr('class'); // Remove all classes from the cloned form

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

});

Achievement

No blank forms are being captured anymore.

Snippet/Screenshot/Link

Link: Ticket