我正在尝试将4m医疗软件与wordpress联系表单7插件集成。我已经添加了他们发送到functions.php文件的代码,当我尝试填写联系表单并点击发送按钮时,它给了我这个错误: -
JSON解析错误:无法解析JSON字符串
这是我在functions.php中添加的代码: -
/*code to track*/
function fms_cf7_post_form($cf7_form){
$cf7_id = (int)$cf7_form->id();
$post_data = $_POST;
$url = 'http://app.4mmedicalsoft.com/api/leads/register';
if (in_array($cf7_id, ['508']))
{
$webkey='0bEUmO0FX0g6P5Aak2chm014UVIzQXFkcjIyNjg1T3hUT0Z2dGJKbmMxS0thbVpNWWFLRGhtVmlnWkRtbmNycTNYcm9aN2lkU2p4N1pHUTBSVmFkUnZMOXBPSE10U01xWnc0TG9pT1lxbjZ3ZnpNU0dudFoxeGhubDU3RjZOZXRaOWg0RTJxUEQ5Mkc1NGxKQ3FndVIzeTJJWnpjRm5rK0dWaUVWK0lCYzBsTVpETmk5dml1S0NJZnEzcz0%3D';
$fms_array_format = array(
'lead' => [ "origin" =>"2",
"fullName"=> $post_data["your-name"],
"email"=> $post_data["your-email"],
"message"=> $post_data["your-message"]
],
'api' => ["payload" => $webkey // THE WEBKEY VALUE (ABOVE)
]
);
// IF ANY OF THE REQUIRED FIELDS ABOVE ARE NOT PART OF YOUR CONTACT FORM DO NOT ICLUDE THEM IN THE SUBMISSION TO 4Ms API ENDPOINT
$response = wp_remote_post($url, array(
'method' => 'POST',
'body' => $fms_array_format
));
// The $response will be json string with a 'status' => '__success' OR 'status' => '__failed'
// If Success it will return also as part of a 'data' parameter all the data submitted to 4Ms from via this function (i.e. $fms_array_format)
}
echo json_encode($response);
}
add_action('wpcf7_before_send_mail', 'fms_cf7_post_form');