1/* global gtag, dataLayer, convertSignup, plausible */ 2 3/** 4 * Contact Sales Form 5 * JS Dependencies: 6 * â jQuery 7 * â jQuery Validation: https://jqueryvalidation.org/ 8 * â JCF Jquery plugin: https://www.psd2html.com/js-custom-forms/ 9 * WP Dependencies 10 * â WP Contact Form 7 11 */ 12 13const contactSalesForm = (($) => { 14 return { 15 /** 16 * Remove CF7's default validation error tips to prevent duplicate error messages 17 * CF7 adds `.wpcf7-not-valid-tip` elements which conflict with jQuery Validation errors 18 */ 19 removeCF7ValidationTips() { 20 // Remove existing CF7 error tips 21 document.querySelectorAll('.wpcf7-not-valid-tip').forEach((el) => el.remove()); 22 23 // Listen for CF7 invalid event and remove tips when they appear 24 document.addEventListener('wpcf7invalid', () => { 25 document.querySelectorAll('.wpcf7-not-valid-tip').forEach((el) => el.remove()); 26 }); 27 28 // Also observe DOM changes to catch dynamically added CF7 tips 29 const form = document.querySelector('.main-contact-sales-form .wpcf7-form'); 30 if (form) { 31 const observer = new MutationObserver((mutations) => { 32 mutations.forEach((mutation) => { 33 mutation.addedNodes.forEach((node) => { 34 if ( 35 node.nodeType === 1 && 36 node.classList?.contains('wpcf7-not-valid-tip') 37 ) { 38 node.remove(); 39 } 40 }); 41 }); 42 }); 43 observer.observe(form, { childList: true, subtree: true }); 44 } 45 }, 46 validateForm() { 47 $('.wpcf7-form').validate({ 48 validClass: 'valid u-my-4', 49 errorElement: 'label', 50 errorClass: 'error u-my-4', 51 highlight(element, errorClass) { 52 $(element).removeClass('valid'); 53 $(element).addClass(errorClass); 54 }, 55 rules: { 56 your_name: { required: true, minlength: 3 }, 57 your_email: { 58 required: true, 59 email: true, 60 }, 61 }, 62 messages: { 63 your_name: { 64 minlength: jQuery.validator.format('At least {0} characters required!'), 65 }, 66 }, 67 }); 68 }, 69 sendAnalytics() { 70 document.addEventListener( 71 'wpcf7mailsent', 72 (event) => { 73 // Add Envelope Image in response message 74 $('.wpcf7-response-output').addClass('_form-thank-you flex flex-column'); 75 76 contactSalesForm.trackFormSubmission().then((response) => { 77 console.log('Form submission tracked'); 78 }); 79 }, 80 false 81 ); 82 }, 83 async trackFormSubmission() { 84 const formData = new URLSearchParams(); 85 formData.append('action', 'plausible_new_event'); 86 formData.append('urlSource', window.location.href); 87 formData.append('name', 'Submitted Enterprise Form'); 88 formData.append('category', 'enterprise-form'); 89 90 try { 91 const response = await fetch(themeple_global.ajaxurl, { 92 method: 'POST', 93 headers: { 94 'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8', 95 }, 96 body: formData.toString(), 97 }); 98 99 return await response.json(); 100 } catch (error) { 101 return null; 102 } 103 }, 104 }; 105})(jQuery); 106contactSalesForm.removeCF7ValidationTips(); 107contactSalesForm.validateForm(); 108contactSalesForm.sendAnalytics();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.