首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将Contact form 7变量传递给屏幕

将Contact form 7变量传递给屏幕
EN

Stack Overflow用户
提问于 2021-09-22 14:39:17
回答 1查看 66关注 0票数 0

使用contact Form7,我发布了一个API字符串,并接收$Body格式的响应。

我想将这个响应打印到屏幕上,但是var_dump、echo和print还没有尝试在页面上显示值。

我已经设法登录到错误日志,但是想知道有什么方法可以将这个变量传递给页面吗?

代码语言:javascript
复制
add_action('wpcf7_mail_sent','Kiri_cf7_api_sender');

 function Kiri_cf7_api_sender ( $contact_form) {
     if ( $contact_form->title === 'Quote_form')
     {
        $submission = WPCF7_Submission::get_instance();

        if ($submission) 
        {
            $posted_data = $submission->get_posted_data();
            
            $name = $posted_data["your-name"];
            $surname = $posted_data["your-name2"];
            $phone = $posted_data["tel-922"];
            
            //example url//
            $url = www.mytestapi.com?$name&$surname&$phone;
                        
            $response = wp_remote_post ($url);
            $body = wp_remote_retrieve_body( $response );
            
                     ob_start();                     // start buffer capture

    var_dump($name);
    var_dump($surname);
    var_dump($phone);
    
    $contents = ob_get_contents();  // put the buffer into a variable
    ob_end_clean();                 // end capture
    error_log($contents); 
        }
     }
 }
EN

回答 1

Stack Overflow用户

发布于 2021-10-01 08:14:34

HTML v4.11 (本周发布,v4.11rc1在GitHub repo上可用)包括一个方便的过滤器,可以将自定义Smart Grid-layout添加到响应输出中。

代码语言:javascript
复制
add_filter( 'cf7sg_submission_success_message','change_submission_response',10,3);
/*
* filter the response message for a successfull submission including HTML markup.
* @param String $message to submit
* @param Array $data $field_name=>$value pair of submitted data.
* @param String $cf7key unique form key
* @return String a message which can include HTML markup.
*/
function change_submission_response($message, $data, $cf7key){
  //validate this is the correct form being submitted.
  if('my-form'==$cf7key ){
    $message = 'thank you, please track your request <a href="http://google.com">here</a>';
  }
  return $message;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69286422

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档