我有一个联系人表单7,它向API发送信息。我想在前端显示API响应。
我记录用户信息,然后使用wp\\u remote\\u post和我的示例url发布它。我希望能够在前端显示API响应/$正文。我已将其设置为在调试日志中捕获它,但想知道是否有方法将其发布到我的表单所在的前端。
正常的Var Dump和print\\r不起作用,因为联系人表单7是一个Ajax函数。
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);
}
}
}