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

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

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

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

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

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...