function hubspot_insert_lead in HubSpot 6.2
Same name and namespace in other branches
- 6 hubspot.module \hubspot_insert_lead()
- 7 hubspot.module \hubspot_insert_lead()
Executes the HubSpot API POST to insert a lead
Parameters
string $formURL HubSpot-provided POST URL to submit to:
array $fields Form fields, such as name and contact info:
Return value
array with fields Data, Error, and HTTPCode. Error is the HTTP error message from drupal_http_request, and HTTPCode is the HTTP response code of the request.
1 call to hubspot_insert_lead()
- hubspot_webform_submission_insert in ./
hubspot.module - Intercepts the WebForm submission and send it off to HubSpot. Implements hook_webform_submission_insert().
File
- ./
hubspot.module, line 178 - Sends Webform results to HubSpot's Leads API by using Webform's provided hooks.
Code
function hubspot_insert_lead($formURL, $fields) {
$strPost = "";
// Turn $fields into POST-compatible list of parameters
foreach ($fields as $fieldName => $fieldValue) {
$strPost .= urlencode($fieldName) . '=';
$strPost .= urlencode($fieldValue);
$strPost .= '&';
}
$strPost = rtrim($strPost, '&');
// nuke the final ampersand
// send POST data
$r = drupal_http_request($formURL, array(
'Content-Type' => 'application/x-www-form-urlencoded',
), 'POST', $strPost);
return array(
'Data' => isset($r->data) ? $r->data : '',
'Error' => isset($r->error) ? $r->error : '',
'HTTPCode' => $r->code,
);
}