Fix "Uncaught ReferenceError: captainform_preload_form_popup is not defined"

Written by Dan Mossop

Are your CaptainForms not working, or are you seeing "Uncaught ReferenceError: captainform_preload_form_popup is not defined" in your website's console? This error can disrupt the functionality of your site's features, such as accordions or tabs that suddenly refuse to work. Fortunately, this issue is resolvable, most commonly associated with conflicts arising from script deferral in caching and optimization plugins like WP Rocket.

Resolve the "Uncaught ReferenceError: captainform_preload_form_popup" error by:

  1. Temporarily disabling WP Rocket to check if errors stop.
  2. If resolved, exclude 'captainform-form-popup.js' from WP Rocket's script deferral.
  3. Clear cache and verify if site features work without error.

Understanding the Error

The error indicates that the browser is attempting to call a function from the CaptainForm plugin before the function has been loaded and defined in the global scope. This scenario is common when JavaScript scripts are deferred in order to improve the loading times of web pages.

WP Rocket Configuration

If you are using WP Rocket, then to resolve the JavaScript error, you'll often need to adjust the settings of your caching plugin to ensure the necessary scripts are not deferred. Here are the steps to fine-tune WP Rocket:

Troubleshoot with WP Rocket Disabled:

Temporarily disable WP Rocket on your website. By doing so, you check if script deferral is the cause of the issue. If the error vanishes and the Captain Forms on your site start work correctly, you've found the culprit.

Exclude Scripts from Deferral:

Rather than keeping WP Rocket disabled (which could impact your site's performance), you can tell WP Rocket to exclude the CaptainForm script from being deferred. To do this, you'll need to:

  • Access WP Rocket's settings in your WordPress admin panel.
  • Navigate to the File Optimization tab.
  • Scroll to the JavaScript section where you have the option to defer JavaScript files.
  • Add the name of the JavaScript file – captainform-form-popup.js – to the exclusion list.

This exclusion ensures the script loads in the correct order, allowing the CaptainForm’s functions to define before any attempts to use them. Consult WP Rocket's documentation for detailed guidance: Exclude files from Load JavaScript Deferred.

Verify the Results:

After making these changes, clear your site’s cache and browser cache. Then verify that the site is functioning correctly with no errors in the console.

Script deferral is a powerful speed optimization, but occasionally, it may need tweaking to play nicely with all your plugins. By following these steps, you'll be able to enjoy both the speed advantages of WP Rocket and the full functionality of the CaptainForm plugin.

Supercharge Your Posts with AI-Generated CTAs

Transform your WordPress site with WP Magic CTAs. Customize call-to-actions for each post to increase engagement effortlessly. Perfect for resolving site issues like script errors and optimizing your posts.

About Dan Mossop

Dan is a Scottish-born web developer, now living in Brisbane with his wife and son. He has been sharing tips and helping users with Divi since 2014. He created Divi Booster, the first Divi plugin, and continues to develop it along with 20+ other Divi plugins. Dan has a PhD in Computer Science, a background in web security and likes a lot of stuff, 

0 Comments

Submit a Comment

Comments are manually moderated and approved at the time they are answered. A preview is shown while pending but may disappear if your are cookies cleared - don't worry though, the comment is still in the queue.

Your email address will not be published. Required fields are marked *.

We may earn a commission when you visit links on our website.

Latest From Divi Booster

Fix Divi Text Module "Regular" Font Weight Not Working

Are you encountering an issue where the font weights in Divi's Text Module don't seem to apply as expected? In particular, you might find that when you set the text module's body text font weight to "Regular", your font is actually assigned a weight of 500 instead of...

Make the Divi Gallery Module Swipeable

The Divi Gallery Module comes with a slider mode that lets you display images in a slider with clickable left/right arrows to scroll through the images. For mobile / touchscreen users, you can improve the user experience by allowing your user to swipe to navigate to...

How to Use Divi Dynamic Content in Woo Modules Product Selector

Divi's Dynamic Content is a powerful feature that lets you populate your Divi modules and theme builder templates with data pulled in various sources, such as custom fields. This allows for efficient organization and maintenance of your sites.Unfortunately, Divi's...

Removing Gaps in Divi Builder Layouts

Designing a seamless, professional-looking website is often about managing space effectively. Gaps in Divi Builder - particularly excessive white space between sections, rows, or modules - can disrupt your layout, leading to a fragmented and less engaging user...

Random Divi Posts