我对 php/curl 和重力形式的钩子相当陌生。我有 5 个表单,我正在尝试设置以使用重力表单 gform_after_submission 挂钩,以便将 xml 数据发送给第三方(运行 sql server 的 sbs Web 服务)。
这是我已经拥有的。
add_action('gform_after_submission_73', 'post_to_third_party', 10, 2);
function post_to_third_party($entry, $form) {
$post_url = 'http://mywebsite.co.uk/customers?clientid=1599999&secret=123';
$body = array(
'brand' => $entry['20'],
'product' => $entry['22'],
'form_id' => $entry['21'],
'title' => $entry['24'],
'fname' => $entry['23'],
'lname' => $entry['17'],
'postcode' => $entry['14'],
'address1' => $entry['2.1'],
'address2' => $entry['2.2'],
'town' => $entry['2.3'],
'county' => $entry['2.4']
);
$xml = '
<?xml version="1.0" encoding="WINDOWS-1252"?>
<webform>
<brand>$brand</brand>
<product>$product</product>
<form_id>$form_id</form_id>
<title>$title</title>
<fname>$fname</fname>
<lname>$lname</lname>
<postcode>$postcode</postcode>
<address1>$address1</address1>
<address2>$address2</address2>
<town>$town</town>
<county>$county</county>
</webform>';
var_dump($xml);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$output = curl_exec($ch);
echo $output;
curl_close($ch);
}