Trying to get contact form 7 post data to debug to screen

You can’t just dump this data to the screen, because it’s part of an ajax function. You can however dump it to the error log and tail it in bash, or view the output of the log with FTP.

If you do this instead:

add_action( 'wpcf7_before_send_mail', 'my_process_cf7_form_data' );
function my_process_cf7_form_data() {

    $submission = WPCF7_Submission::get_instance();
        if ( $submission ) {
            $posted_data = $submission->get_posted_data();    
    }

    ob_start();
    var_dump($posted_data);
    error_log(ob_get_clean());

}

then either view your php_error_log for this domain, or if you have wp-debug enabled and error logging to file (in your wp-config.php).

define( 'WP_DEBUG',         true );
define( 'WP_DEBUG_LOG',     true );

then you can view the debug.log in wp-content folder.

Leave a Comment