You are here

function hubspot_webform_insert_lead in HubSpot 7.2

Same name and namespace in other branches
  1. 7.3 hubspot_webform/hubspot_webform.module \hubspot_webform_insert_lead()

Executes the HubSpot API POST to insert a lead.

Parameters

string $portal_id: HubSpot Portal ID to submit to.

string $form_guid: HubSpot-provided Form API GUID to submit to.

array $fields: Form fields, such as name and contact info.

Return value

array An associative array containing:

1 call to hubspot_webform_insert_lead()
hubspot_webform_submit in hubspot_webform/hubspot_webform.module
Form handler for pardot_webform_form_alter().

File

hubspot_webform/hubspot_webform.module, line 131
Sends Webform results to HubSpot's Forms API.

Code

function hubspot_webform_insert_lead($portal_id, $form_guid, $fields) {
  $str_post = drupal_http_build_query($fields);

  // Send POST data.
  $result = drupal_http_request('https://forms.hubspot.com/uploads/form/v2/' . $portal_id . '/' . $form_guid, array(
    'headers' => array(
      'Content-Type' => 'application/x-www-form-urlencoded',
    ),
    'method' => 'POST',
    'data' => $str_post,
  ));
  return array(
    'Data' => isset($result->data) ? $result->data : '',
    'Error' => isset($result->error) ? $result->error : '',
    'HTTPCode' => $result->code,
    'POST' => $str_post,
  );
}