You are here

function simplenews_block_form in Simplenews 5

Same name and namespace in other branches
  1. 6.2 includes/simplenews.subscription.inc \simplenews_block_form()
  2. 6 simplenews.module \simplenews_block_form()
  3. 7.2 includes/simplenews.subscription.inc \simplenews_block_form()
  4. 7 includes/simplenews.subscription.inc \simplenews_block_form()

Show block subscription form.

1 string reference to 'simplenews_block_form'
simplenews_forms in ./simplenews.module
Implementation of hook_forms

File

./simplenews.module, line 1076

Code

function simplenews_block_form($tid) {
  global $user;
  $form = array();
  if ($user->uid) {
    if (simplenews_user_is_subscribed($user->mail, $tid)) {
      $submit_text = t('Unsubscribe');
      $form['action'] = array(
        '#type' => 'value',
        '#value' => 'unsubscribe',
      );
    }
    else {
      $submit_text = t('Subscribe');
      $form['action'] = array(
        '#type' => 'value',
        '#value' => 'subscribe',
      );
    }
    $form['display_mail'] = array(
      '#title' => t('User'),
      '#value' => check_plain($user->name),
      '#prefix' => '<div class="user-name">',
      '#suffix' => '</div>',
    );
    $form['mail'] = array(
      '#type' => 'value',
      '#value' => $user->mail,
    );
  }
  else {
    $form['mail'] = array(
      '#type' => 'textfield',
      '#title' => t('E-mail'),
      '#size' => 20,
      '#maxlength' => 128,
      '#required' => TRUE,
    );
    $form['action'] = array(
      '#type' => 'radios',
      '#default_value' => 'subscribe',
      '#options' => array(
        'subscribe' => t('Subscribe'),
        'unsubscribe' => t('Unsubscribe'),
      ),
    );
  }

  // All block forms use the same validate and submit function.
  // 'tid' carries the tid for processing of the right newsletter issue term.
  $form['tid'] = array(
    '#type' => 'value',
    '#value' => $tid,
  );
  $form['#base'] = 'simplenews_block_form';
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => isset($submit_text) ? $submit_text : t('Submit'),
  );
  return $form;
}