Ecommerce Shopify WordPress Discussion

Why isn't the wpcf7submit event working in Contact Form 7 with JavaScript?

I'm trying to capture the wpcf7submit event from a Contact Form 7 form on my WordPress site to trigger an alert when the form is successfully submitted. However, the event doesn't seem to trigger the function I've attached to it. Here's the code snippet I'm using within a script tag in my footer.php file, after the body content: <div class="contact-form"> <h2 class="contact-form__title">Contact</h2> <?php echo apply_shortcodes('[contact-form-7 id="fbe8376" title="Contact Form 1"]'); ?> </div> document.addEventListener('DOMContentLoaded', function() { const wpcf7Elm = document.querySelector('.wpcf7'); console.log(wpcf7Elm); // For debugging: to verify that the element is being selected. wpcf7Elm.addEventListener('wpcf7submit', function(event) { alert("Fire!"); }, false); }); I've confirmed that the .wpcf7 element exists in the DOM by checking the console output, which correctly logs the element. This indicates that the script correctly waits for the DOM to be fully loaded before attempting to attach the event listener. Despite this, the alert doesn't appear when the form is submitted. I've checked for JavaScript errors in the console but haven't found any that seem related. The form itself works fine and submits as expected. I'm wondering if there are any known issues with capturing wpcf7submit events like this, or if there's something wrong with how I'm trying to attach the event listener. Could there be a conflict with another script, or does Contact Form 7 require a different approach to capture submission events?
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.