Troubleshooting Common Issues with the Contact Form 7 Database Addon (CFDB7)
Content
The Contact Form 7 Database Addon (CFDB7) is a popular and powerful tool for saving form submissions from the Contact Form 7 plugin. However, like any software, users can occasionally run into issues. Based on community discussions, here are some of the most common problems and their potential solutions.
1. Forms Not Appearing in the List
The Problem: Users report that not all of their Contact Form 7 forms are visible in the CFDB7 form list. This is a frequent issue on multilingual sites using plugins like WPML or Polylang.
Why It Happens: The plugin's query to fetch forms may not be fully compatible with how translation plugins duplicate and manage form posts.
Potential Solutions:
- Check the pagination at the bottom of the forms list, as forms might be on a different page.
- This appears to be a known compatibility issue. Users may need to wait for an official update from the 'Contact Form 7 Database Addon – CFDB7' team that addresses multilingual queries.
2. PHP 8.x Compatibility Error on Multisite
The Problem: Upon activating the plugin on a WordPress multisite installation running PHP 8.0 or 8.1, a fatal error occurs: Fatal error: Uncaught Error: Call to a member function add_cap() on null.
Why It Happens: The plugin attempts to add capabilities before all necessary WordPress functions are loaded in the multisite environment under newer PHP versions.
The Solution: A workaround found by the community is to add the following code to your theme's functions.php file. This ensures the required user role functions are loaded.
if ( !function_exists( 'populate_roles' ) ) {
require_once( ABSPATH . 'wp-admin/includes/schema.php' );
}
populate_roles();
3. Excluding Specific Forms from Being Saved
The Problem: A user may want to prevent CFDB7 from saving submissions for certain forms, for example, to avoid storing spam submissions in the database.
The Solution: This requires a two-part code modification.
- Add the following code to your theme's
functions.phpfile to prevent the plugin from saving submissions for forms with IDs 4465 and 5515 (replace these IDs with your own).$cfdb_exclude_ids = array( 4465, 5515); add_action( 'wpcf7_before_send_mail', 'exclude_wpcf7_before_send_mail', 9); function exclude_wpcf7_before_send_mail( $form ){ global $cfdb_exclude_ids; $id = $form->id(); if( in_array($id , $cfdb_exclude_ids) ){ remove_action( 'wpcf7_before_send_mail', 'cfdb7_before_send_mail'); } } - Modify the plugin file itself to exclude the forms from the admin list. Navigate to
plugins > contact-form-cfdb7 > inc > admin-mainpage.phpand find the$argsarray for the form query. Change it to use'post__not_in' => $cfdb_exclude_ids.
Important Note: Any changes made to the plugin's core files will be overwritten when the plugin is updated. This solution is a temporary workaround.$cfdb_exclude_ids = array( 4465,5515); $args = array( 'post_type' => 'wpcf7_contact_form', 'order' => 'ASC', 'post__not_in' => $cfdb_exclude_ids );
4. Displaying Submission Counts on the Front End
The Problem: Users wish to display the number of submissions for a specific form somewhere on their website's front end.
The Solution: You can retrieve the count by running a custom database query. The following code snippet can be placed in a template file or within a custom function.
global $wpdb;
$cfdb = apply_filters( 'cfdb7_database', $wpdb );
$table_name = $cfdb->prefix.'db7_forms';
$form_post_id = 123; // Change 123 to your actual Form ID
$submission_count = $cfdb->get_var( "SELECT COUNT(*) FROM $table_name WHERE form_post_id = $form_post_id" );
echo $submission_count; // This displays the count
General Advice
- Always create a full backup of your site before adding custom code or modifying plugin files.
- When adding code to your theme's
functions.phpfile, consider using a child theme to prevent your changes from being lost during a theme update. - Many of these solutions are community-provided workarounds. For permanent fixes, keep an eye on the official plugin changelog for updates that address these common issues.
Related Support Threads Support
-
Is it possible to exclude forms?https://wordpress.org/support/topic/is-it-possible-to-exclude-forms/
-
Improve I18N Issues (Based on 1.2.6.6)https://wordpress.org/support/topic/improve-i18n-issues-based-on-1-2-6-6/
-
Make it possiblehttps://wordpress.org/support/topic/make-it-possible/
-
Bug with wpml pluginhttps://wordpress.org/support/topic/bug-with-wpml-plugin/
-
PHP versionhttps://wordpress.org/support/topic/php-version-111/
-
Count entrieshttps://wordpress.org/support/topic/count-entries/
-
complete all listhttps://wordpress.org/support/topic/complete-all-list/
-
Pagination in front end listhttps://wordpress.org/support/topic/pagination-in-front-end-list/
-
unistall.phphttps://wordpress.org/support/topic/unistall-php/
-
WPML compatibilityhttps://wordpress.org/support/topic/wpml-compatibility-296/
-
More elements per pagehttps://wordpress.org/support/topic/more-elements-per-page/
-
Not showing all formshttps://wordpress.org/support/topic/not-showing-all-forms/
-
form counthttps://wordpress.org/support/topic/form-count/
-
Can get all the informationhttps://wordpress.org/support/topic/can-get-all-the-information/
-
Shortcodeshttps://wordpress.org/support/topic/shortcodes-466/
-
Usageshttps://wordpress.org/support/topic/usages/