尝试获取联系表 7 post 数据以调试到屏幕
Trying to get contact form 7 post data to debug to screen
我一直在尝试获取联系表 7 post 数据来调试表单提交,以便我可以将其用于我正在尝试使用的插件。但是,当我使用 var_dump 或 print_r 时,我无法在任何地方获取数据。
我已经开始了。
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);
}
但是我没有得到任何输出。
您不能只将此数据转储到屏幕上,因为它是 ajax 函数的一部分。但是,您可以将其转储到错误日志中并将其添加到 bash 中,或者使用 FTP.
查看日志的输出
如果改为这样做:
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());
}
然后查看此域的 php_error_log,或者如果您启用了 wp-debug 并将错误记录到文件(在您的 wp-config.php 中)。
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
然后您可以在 wp-content 文件夹中查看 debug.log。
我设法通过更改邮件内容并将其发送给自己来进行调试,如下所述:
How to change data before sending in Contact form 7?
add_action('wpcf7_before_send_mail', 'w2p_on_submit', 10, 3);
function w2p_on_submit( $form, &$abort, $submission )
{
$debug="1";
$mail = $form->prop( 'mail' );
$new_mail = str_replace( '[your-name]', $debug, $mail );
$form->set_properties( array( 'mail' => $new_mail ) );
return $form;
}
(我无法让日志工作。)
我一直在尝试获取联系表 7 post 数据来调试表单提交,以便我可以将其用于我正在尝试使用的插件。但是,当我使用 var_dump 或 print_r 时,我无法在任何地方获取数据。
我已经开始了。
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);
}
但是我没有得到任何输出。
您不能只将此数据转储到屏幕上,因为它是 ajax 函数的一部分。但是,您可以将其转储到错误日志中并将其添加到 bash 中,或者使用 FTP.
查看日志的输出如果改为这样做:
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());
}
然后查看此域的 php_error_log,或者如果您启用了 wp-debug 并将错误记录到文件(在您的 wp-config.php 中)。
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
然后您可以在 wp-content 文件夹中查看 debug.log。
我设法通过更改邮件内容并将其发送给自己来进行调试,如下所述: How to change data before sending in Contact form 7?
add_action('wpcf7_before_send_mail', 'w2p_on_submit', 10, 3);
function w2p_on_submit( $form, &$abort, $submission )
{
$debug="1";
$mail = $form->prop( 'mail' );
$new_mail = str_replace( '[your-name]', $debug, $mail );
$form->set_properties( array( 'mail' => $new_mail ) );
return $form;
}
(我无法让日志工作。)