You are here

function constant_contact_signup_form in Constant Contact 6.3

Same name and namespace in other branches
  1. 6.2 constant_contact.module \constant_contact_signup_form()
  2. 7.3 constant_contact.module \constant_contact_signup_form()

Shows the custom signup form, added using a block

1 string reference to 'constant_contact_signup_form'
constant_contact_block in ./constant_contact.module
Enables us to place a signup form into a block

File

./constant_contact.module, line 851

Code

function constant_contact_signup_form(&$form_state) {
  $cc = constant_contact_create_object();
  $form = array();
  $show_selection = variable_get('cc_block_show_list_selection', CC_BLOCK_SHOW_LIST_SELECTION);
  $selection_format = variable_get('cc_block_list_selection_format', CC_LIST_SELECTION_FORMAT);
  $show_format_choice = variable_get('cc_show_format_choice', CC_SHOW_FORMAT_CHOICE);
  $default_subscribe_format = variable_get('cc_subscribe_format', CC_SUBSCRIBE_FORMAT);
  $form_block_fields = variable_get('cc_form_block_fields', array());
  $email_field_position = variable_get('cc_email_field_position', 1);
  if (is_array($form_block_fields)) {
    $form_block_fields['_email'] = 1;

    /* dummy entry so we get enough for the email field */
    $current_pos = 1;
    foreach ($form_block_fields as $field => $enabled) {
      if ($enabled) {
        if ($current_pos == $email_field_position) {
          $form['cc_email'] = array(
            '#type' => 'textfield',
            '#title' => t('Email'),
            '#size' => 30,
            '#required' => TRUE,
          );
        }
        if ($field != '_email') {
          $fieldname = str_replace(' ', '', $field);
          $form["cc_{$fieldname}"] = array(
            '#type' => 'textfield',
            '#title' => $field,
            '#size' => 30,
            '#required' => true,
            '#default_value' => $form_state['values']["cc_{$fieldname}"],
          );
        }
        ++$current_pos;
      }
    }
  }
  if ($show_selection && is_object($cc)) {
    $exclude_lists = variable_get('cc_block_lists', '');
    $lists = constant_contact_get_lists($cc);
    if (!is_array($exclude_lists)) {
      $exclude_lists = array();
    }
    $options = array();
    foreach ($lists as $list_id => $list_name) {
      if (!in_array($list_id, $exclude_lists)) {
        $options[$list_id] = $list_name;
      }
    }
    if (count($options) > 0) {
      if ($selection_format == 'select') {
        $field_type = 'select';
      }
      else {
        $field_type = 'checkboxes';
      }
      $form['cc_newsletter_lists'] = array(
        '#type' => $field_type,
        '#title' => variable_get('cc_signup_title', CC_SIGNUP_TITLE),
        '#description' => variable_get('cc_signup_description', CC_SIGNUP_DESCRIPTION),
        '#options' => $options,
        '#required' => TRUE,
      );
      if ($selection_format == 'select') {
        $form['cc_newsletter_lists']['#multiple'] = true;
        $form['cc_newsletter_lists']['#size'] = count($options);
      }
    }
  }
  if ($show_format_choice) {
    $form['cc_email_format'] = array(
      '#type' => 'radios',
      '#title' => t('Email Format'),
      '#description' => 'You can receive emails in Text or HTML format',
      '#default_value' => $default_subscribe_format,
      '#options' => array(
        'Text' => 'Text',
        'HTML' => 'HTML',
      ),
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Signup'),
  );
  return $form;
}