You are here

function _webform_edit_hubspot_url in HubSpot 6

Same name and namespace in other branches
  1. 6.2 hubspot.module \_webform_edit_hubspot_url()
  2. 7 hubspot.module \_webform_edit_hubspot_url()

Implements _webform_edit_component() to adjust the HubSpot POST URL edit page.

File

./hubspot.module, line 181
Sends Webform results to HubSpot's Leads API by using Webform's provided hooks.

Code

function _webform_edit_hubspot_url($component) {
  $form = array();

  // Disable Description box
  $form['extra']['description'] = array();
  $form['value'] = array(
    '#type' => 'textfield',
    '#title' => t('HubSpot POST URL'),
    '#description' => t('The API POST URL provided under HubSpot\'s Lead API settings for this form.'),
    '#default_value' => $component['value'],
  );

  // Hide display options
  $form['display'] = array(
    '#type' => 'markup',
  );

  // Overwrite the "Label" field to provide a better description
  $form['name'] = array(
    '#type' => 'textfield',
    '#default_value' => $component['name'],
    '#title' => t('Label'),
    '#description' => t('The name of this field. This field will not be displayed to users submitting the form.'),
    '#required' => TRUE,
    '#weight' => -10,
    '#maxlength' => 255,
  );
  $form_fields = array();
  $result = db_query('SELECT cid, form_key, name, type FROM {webform_component} WHERE type <> \'hubspot_url\' AND nid = %d ORDER BY weight, name', $component['nid']);
  while ($c = db_fetch_array($result)) {
    $form_fields[$c['cid']] = sprintf('%s (%s)', $c['name'], $c['form_key']);
  }
  $form['extra']['custom_fields'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Custom fields'),
    '#options' => $form_fields,
    '#default_value' => isset($component['extra']['custom_fields']) ? array_keys(array_filter($component['extra']['custom_fields'])) : array_keys($form_fields),
    '#description' => t('Select which fields should be sent to HubSpot'),
    '#weight' => 0,
    '#required' => FALSE,
  );
  return $form;
}