You are here

function simplenews_subscriptions_page_form in Simplenews 6.2

Same name and namespace in other branches
  1. 7.2 includes/simplenews.subscription.inc \simplenews_subscriptions_page_form()
  2. 7 includes/simplenews.subscription.inc \simplenews_subscriptions_page_form()

FAPI PAGE subscription form.

See also

simplenews_subscriptions_page_form_validate()

simplenews_subscriptions_page_form_submit()

1 string reference to 'simplenews_subscriptions_page_form'
simplenews_menu in ./simplenews.module
Implementation of hook_menu().

File

includes/simplenews.subscription.inc, line 215
(Un)subscription and (un)subscription confirmation

Code

function simplenews_subscriptions_page_form(&$form_state) {
  global $user;
  $subscription = simplenews_get_subscription($user);
  $form = array();
  $options = array();
  $default_value = array();

  // Get newsletters for subscription form checkboxes.
  // Newsletters with opt-in/out method 'hidden' will not be listed.
  foreach (simplenews_get_newsletters(variable_get('simplenews_vid', '')) as $newsletter) {
    $options[$newsletter->tid] = check_plain($newsletter->name);
    $default_value[$newsletter->tid] = FALSE;
  }
  $form['subscriptions'] = array(
    '#type' => 'fieldset',
    '#description' => t('Select the newsletter(s) to which you want to subscribe or unsubscribe.'),
  );
  $form['subscriptions']['newsletters'] = array(
    '#type' => 'checkboxes',
    '#options' => $options,
    '#default_value' => array_merge($default_value, (array) $subscription->tids),
  );

  // If current user is logged in, just display email.
  // Anonymous users see an email box and will receive confirmations
  if ($subscription->mail) {
    $form['subscriptions']['#title'] = t('Subscriptions for %mail', array(
      '%mail' => $subscription->mail,
    ));
    $form['subscriptions']['mail'] = array(
      '#type' => 'value',
      '#value' => $subscription->mail,
    );
    $form['update'] = array(
      '#type' => 'submit',
      '#value' => t('Update'),
      '#weight' => 20,
    );
  }
  else {
    $form['subscriptions']['#title'] = t('Manage your newsletter subscriptions');
    $form['subscriptions']['mail'] = array(
      '#type' => 'textfield',
      '#title' => t('email'),
      '#size' => 20,
      '#maxlength' => 128,
      '#weight' => 10,
      '#required' => TRUE,
    );
    $form['subscribe'] = array(
      '#type' => 'submit',
      '#value' => t('Subscribe'),
      '#weight' => 20,
    );
    $form['unsubscribe'] = array(
      '#type' => 'submit',
      '#value' => t('Unsubscribe'),
      '#weight' => 30,
    );
  }
  $form['#validate'][] = 'simplenews_subscriptions_page_form_validate';
  $form['#submit'][] = 'simplenews_subscriptions_page_form_submit';
  return $form;
}