You are here

function campaignmonitor_general_form in Campaign Monitor 6

Same name and namespace in other branches
  1. 5.2 campaignmonitor.module \campaignmonitor_general_form()
  2. 5 campaignmonitor.module \campaignmonitor_general_form()
  3. 6.2 campaignmonitor.module \campaignmonitor_general_form()
1 string reference to 'campaignmonitor_general_form'
template_preprocess_campaignmonitor_block_content in ./campaignmonitor.module
Block template preprocessor

File

./campaignmonitor.module, line 182

Code

function campaignmonitor_general_form() {
  global $user;
  $name = '';
  $email = '';
  $default = false;

  // Check if the profile module is installed. If it is, use the name element of the profile
  if (module_exists("profile")) {
    profile_load_profile($user->uid);
    $name = $user->profile_name;
  }
  if ($user->uid != 0) {
    $email = $user->mail;
    if (_campaignmonitor_is_subscribed(variable_get('campaignmonitor_api_key', ''), variable_get('campaignmonitor_list_id', 0), $email)) {
      $default = true;

      // Also if subscribed get name
      $subscriber = _campaignmonitor_get_subscriber(variable_get('campaignmonitor_api_key', ''), variable_get('campaignmonitor_list_id', 0), $email);
      $name = $subscriber['name'];
    }
    else {
      $default = false;
    }
  }
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#size' => 20,
    '#maxlength' => 50,
    '#required' => TRUE,
    '#default_value' => $name,
  );
  $form['email'] = array(
    '#type' => 'textfield',
    '#title' => t('Email'),
    '#size' => 20,
    '#maxlength' => 100,
    '#required' => TRUE,
    '#default_value' => $email,
  );
  $form['unsubscribe_newsletter'] = array(
    '#type' => 'checkbox',
    '#title' => t('Unsubscribe'),
    '#default_value' => $default,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );
  return $form;
}