You are here

function simplenews_block_form in Simplenews 7.2

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

FAPI BLOCK subscription form.

Parameters

$newsletter_id: 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
Implements hook_forms().

File

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

Code

function simplenews_block_form($form, &$form_state, $newsletter_id) {
  global $user;
  $form = array();
  $submit_text = t('Subscribe');
  if ($user->uid) {
    if (simplenews_user_is_subscribed($user->mail, $newsletter_id)) {
      $submit_text = t('Unsubscribe');
      $form['action'] = array(
        '#type' => 'value',
        '#value' => 'unsubscribe',
      );
      $form['#attributes'] = array(
        'class' => array(
          'simplenews-unsubscribe',
        ),
      );
    }
    else {
      $form['action'] = array(
        '#type' => 'value',
        '#value' => 'subscribe',
      );
      $form['#attributes'] = array(
        'class' => array(
          'simplenews-subscribe',
        ),
      );
    }
    $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' => 'value',
      '#value' => 'subscribe',
    );
    $form['#attributes'] = array(
      'class' => array(
        'simplenews-subscribe',
      ),
    );
  }

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