【问题标题】:Trying to get contact form 7 post data to debug to screen试图让联系表格 7 发布数据以调试到屏幕
【发布时间】:2020-06-07 05:30:39
【问题描述】:

我一直在尝试获取联系表单 7 发布数据来调试表单提交,以便我可以将它用于我正在尝试处理的插件。但是,当我使用 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);
}

但我没有得到任何输出。

【问题讨论】:

    标签: wordpress contact-form-7


    【解决方案1】:

    我设法通过更改邮件内容并将其发送给自己进行了调试,如下所述: 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;
    }
    

    (我无法让日志工作。)

    【讨论】:

      【解决方案2】:

      您不能只将这些数据转储到屏幕上,因为它是 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。

      【讨论】:

        猜你喜欢
        • 2011-10-29
        • 2021-08-19
        • 1970-01-01
        • 2022-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-07-18
        相关资源
        最近更新 更多