我正在使用API将表单数据提交到第三方CRM数据库。
这是表格的html ......
<div class="column last">
<label for="role">What is your role?</label>
<select name="role" id="role">
<option value="noresponse">Please select one</option>
<option value="reseller">Reseller</option>
<option value="researcher">Researcher</option>
<option value="end-user">End-user</option>
<option value="other">Other</option>
</select>
</div>
这是使用API发送所选字段数据的php。
<?php
//Process a new form submission in HubSpot in order to create a new Contact.
$hubspotutk = $_COOKIE['hubspotutk']; //grab the cookie from the visitors browser.
$ip_addr = $_SERVER['REMOTE_ADDR']; //IP address too.
$hs_context = array(
'hutk' => $hubspotutk,
'ipAddress' => $ip_addr,
'pageUrl' => 'http://www.suntechmed.com/index.php?option=com_chronoforms&chronoform=test_form',
'pageName' => 'Test Form'
);
$hs_context_json = json_encode($hs_context);
//Need to populate these varilables with values from the form.
$str_post = "firstname=" . urlencode($_POST["firstname"])
. "&lastname=" . urlencode($_POST["lastname"])
. "&company=" . urlencode($_POST["company"])
. "&role=" . urlencode($POST["role"])
. "&address=" . urlencode($_POST["address"])
. "&city=" . urlencode($_POST["city"])
. "&state=" . urlencode($_POST["state"])
. "&zip=" . urlencode($_POST["zip"])
. "&email=" . urlencode($_POST["email"])
. "&hs_context=" . urlencode($hs_context_json); //Leave this one be :)'
//replace the values in this URL with your portal ID and your form GUID
$endpoint = 'https://forms.hubspot.com/uploads/form/v2/myHubspotID/b9752739-c9a3-4dc3-bf34-cb23679a41d4';
$ch = @curl_init();
@curl_setopt($ch, CURLOPT_POST, true);
@curl_setopt($ch, CURLOPT_POSTFIELDS, $str_post);
@curl_setopt($ch, CURLOPT_URL, $endpoint);
@curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = @curl_exec($ch); //Log the response from HubSpot as needed.
@curl_close($ch);
echo $response;
?>
简单文本字段的字段使转换正常。
我遇到的问题是具有选择选项的字段(如“角色”)没有进入数据库。
事实上,它甚至没有显示出空场的作用。
如果有人有任何建议,那就太棒了!
答案 0 :(得分:1)
创建一个发送有自己的API写在PHP上你可以通过这样的事情添加用户:
($ donation-&gt; subscribe_to_newsletter === true){ require_once( '系统/厘米/ csrest_subscribers.php');
$wrap = new CS_REST_Subscribers(CS_REST_DONATE_LIST_ID, CS_REST_DONATE_API_KEY);
$result = $wrap->add(array(
'EmailAddress' => $donation->email,
'Name' => sprintf('%s %s', $donation->first_name, $donation->last_name),
'CustomFields' => array(),
'Resubscribe' => true
));
您可以在github
上找到所有php文件甚至一些示例