【发布时间】:2021-08-19 07:40:45
【问题描述】:
我想在提交时将我的 7 数据联系人发送到 API。为此,我使用了以下代码。
add_action('wpcf7_mail_sent','crazy_cf7_api_sender');
function crazy_cf7_api_sender( $contact_form ){
$title = $contact_form -> title;
echo "Test";
if( $title == 'Committee Club'){
$submission = WPCF7_Submission::get_instance();
if( $submission ){
$posted_data = $submission->get_posted_data();
$committee_club = $posted_data['committee-club'];
$language = $posted_data['language'];
$Intrest = $posted_data['Intrest'];
$url = 'https://staging.walee.pk/api/tracking/newWordPressHook';
$args = array(
'method' => 'POST',
'orderId' => 220,
);
$response = wp_remote_post( $url, $args );
// error check
if ( is_wp_error( $response ) ) {
$error_message = $response->get_error_message();
echo "Something went wrong: $error_message";
}
else {
echo 'Response: <pre>';
print_r( $response );
echo '</pre>';
}
}
}
}
我得到了参考
https://www.youtube.com/watch?v=QOjpqHFM9v8
https://wp-kama.com/function/wp_remote_post
但是当我提交表单时,我收到以下错误消息:
{code: "invalid_json", message: "响应不是有效的 json 响应。"}
有人可以帮帮我吗?
谢谢
【问题讨论】:
-
以下是调试联系表单输出的方法 - stackoverflow.com/questions/60361457/… - 在我看来,您的问题似乎是您的 API 调用缺少正确的结构。
标签: php wordpress api wordpress-rest-api