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 Posts

Set Custom CSS IDs for Individual Divi Accordion Items

Assigning unique CSS IDs to specific Divi Accordion items allows for precise control over styling, targeting, and linking within your page content. This ability is particularly useful when you want to apply custom designs or create anchor links to particular accordion...

Enable Swipe Navigation in the Divi Gallery Lightbox

Enabling swipe navigation in the Divi Gallery module's lightbox allows users to seamlessly browse through gallery images by swiping left or right, creating a more interactive and mobile-friendly experience. This functionality can significantly improve user engagement...

Disable Slide-In Animation for Divi Gallery Grid Images

Control how images appear in your Divi Gallery module by toggling the slide-in animation effect for grid layouts. Disabling the slide-in animation allows gallery images to load instantly and appear statically, providing a faster and distraction-free browsing...

Control Image Count Display in Divi Gallery Lightbox

Displaying or hiding the image count in the Divi Gallery module’s lightbox can help customize the user experience, depending on whether you want to give visitors an indication of gallery progress or prefer a cleaner, distraction-free view. The ability to toggle this...

Hide Gallery Image Titles in the Divi Lightbox Overlay

Displaying image titles in the lightbox overlay of the Divi Gallery module can sometimes be distracting or unnecessary, depending on your website’s design and user experience goals. Hiding these titles creates a cleaner and more focused viewing experience for visitors...

Random Posts