You are here

function simplenews_block_form_submit in Simplenews 6

Same name and namespace in other branches
  1. 5 simplenews.module \simplenews_block_form_submit()
  2. 6.2 includes/simplenews.subscription.inc \simplenews_block_form_submit()
  3. 7.2 includes/simplenews.subscription.inc \simplenews_block_form_submit()
  4. 7 includes/simplenews.subscription.inc \simplenews_block_form_submit()
1 string reference to 'simplenews_block_form_submit'
simplenews_block_form in ./simplenews.module
Newsletter (un)subscription form for authenticated and anonymous users.

File

./simplenews.module, line 1355
Simplnews node handling, sent email, newsletter block and general hooks

Code

function simplenews_block_form_submit($form, &$form_state) {
  global $user;
  $tid = $form['#tid'];
  $account = _simplenews_user_load($form_state['values']['mail']);

  // If email belongs to the current registered user, don't send confirmation.
  $confirm = $account->uid && $account->uid == $user->uid ? FALSE : TRUE;
  switch ($form_state['values']['action']) {
    case 'subscribe':
      simplenews_subscribe_user($form_state['values']['mail'], $tid, $confirm);
      if ($confirm) {
        drupal_set_message(t('You will receive a confirmation email shortly containing further instructions on how to complete your subscription.'));
      }
      else {
        drupal_set_message(t('You have been subscribed.'));
      }
      break;
    case 'unsubscribe':
      simplenews_unsubscribe_user($form_state['values']['mail'], $tid, $confirm);
      if ($confirm) {
        drupal_set_message(t('You will receive a confirmation email shortly containing further instructions on how to complete the unsubscription process.'));
      }
      else {
        drupal_set_message(t('You have been unsubscribed.'));
      }
      break;
  }
}