function hubspot_insert_lead in HubSpot 6
Same name and namespace in other branches
- 6.2 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, 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 126 - 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
$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,
);
}