You are here

function simplenews_block_form in Simplenews 6.2

Same name and namespace in other branches
  1. 5 simplenews.module \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()

FAPI BLOCK subscription form.

Parameters

$tid term id of selected newsletter.:

See also

simplenews_block_form_validate()

simplenews_block_form_submit()

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

File

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

Code

function simplenews_block_form(&$form_state, $tid) {
  global $user;
  $form = array();
  $submit_text = t('Subscribe');
  if ($user->uid) {
    if (simplenews_user_is_subscribed($user->mail, $tid)) {
      $submit_text = t('Unsubscribe');
      $form['action'] = array(
        '#type' => 'value',
        '#value' => 'unsubscribe',
      );
      $form['#attributes'] = array(
        'class' => 'simplenews-unsubscribe',
      );
    }
    else {
      $form['action'] = array(
        '#type' => 'value',
        '#value' => 'subscribe',
      );
      $form['#attributes'] = array(
        'class' => 'simplenews-subscribe',
      );
    }
    $form['mail'] = array(
      '#type' => 'value',
      '#value' => $user->mail,
    );
  }
  else {
    $form['mail'] = array(
      '#type' => 'textfield',
      '#title' => t('Email'),
      '#size' => 20,
      '#maxlength' => 128,
      '#required' => TRUE,
    );
    $form['action'] = array(
      '#type' => 'value',
      '#value' => 'subscribe',
    );
    $form['#attributes'] = array(
      'class' => 'simplenews-subscribe',
    );
  }

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