You are here

function campaignmonitor_form_alter in Campaign Monitor 6.3

Same name and namespace in other branches
  1. 5.2 campaignmonitor.module \campaignmonitor_form_alter()
  2. 5 campaignmonitor.module \campaignmonitor_form_alter()
  3. 6 campaignmonitor.module \campaignmonitor_form_alter()
  4. 6.2 campaignmonitor.module \campaignmonitor_form_alter()

Implementation of hook_form_alter().

File

./campaignmonitor.module, line 107
Module that plugs in Campaign Monitor functionality to your Drupal web site. For Campaign Monitor information see: http://www.campaignmonitor.com/

Code

function campaignmonitor_form_alter(&$form, $form_state, $form_id) {
  $display_on = variable_get(CM_DISPLAY_ON, array());
  if ('contact_mail_page' == $form_id && $display_on['contact'] != '0' || 'user_register' == $form_id && $display_on['registration'] != '0' && user_access('join newsletter')) {
    $api_key = variable_get(CM_API_KEY, '');
    $client_id = variable_get(CM_CLIENT_ID, '');
    $lists = campaignmonitor_get_available_lists();
    $not_empty = FALSE;
    $options = array();
    foreach ($lists as $list_id => $list) {
      if ($list->oncontactpage && 'contact_mail_page' == $form_id || $list->onregopage && 'user_register' == $form_id) {
        $options[$list_id] = $list->name;
        $not_empty = TRUE;
      }
    }
    if ($not_empty) {
      $form['subscribe_newsletter'] = array(
        '#type' => 'checkboxes',
        '#title' => check_plain(t(variable_get(CM_CHECKBOX_DISPLAY_TEXT, CM_CHECKBOX_DISPLAY_TEXT_DEFAULT))),
        '#options' => $options,
        '#weight' => 99,
      );
      $form['submit']['#weight'] = 100;
      $form['#submit'][] = '_campaignmonitor_altered_form_submit';
    }
  }
}