使用contact Form7,我发布了一个API字符串,并接收$Body格式的响应。
我想将这个响应打印到屏幕上,但是var_dump、echo和print还没有尝试在页面上显示值。
我已经设法登录到错误日志,但是想知道有什么方法可以将这个变量传递给页面吗?
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);
}
}
}发布于 2021-10-01 08:14:34
HTML v4.11 (本周发布,v4.11rc1在GitHub repo上可用)包括一个方便的过滤器,可以将自定义Smart Grid-layout添加到响应输出中。
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;
}https://stackoverflow.com/questions/69286422
复制相似问题