Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've been trying to get contact form 7 post data to debug the form submission so that I can use it for a plugin I'm trying to work on. However, when I use var_dump or print_r, I can't get the data anywhere.

I've started with this.

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();    
    }
    var_dump($posted_data);
}

But I'm not getting any output.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
981 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...