You are here

function simplenews_block_form_submit in Simplenews 6.2

Same name and namespace in other branches
  1. 5 simplenews.module \simplenews_block_form_submit()
  2. 6 simplenews.module \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 includes/simplenews.subscription.inc
FAPI BLOCK subscription form.

File

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

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.
  // Other addresses receive a confirmation if double opt-in is selected.
  if ($account->uid && $account->uid == $user->uid) {
    $confirm = FALSE;
  }
  else {
    $confirm = variable_get('simplenews_opt_inout_' . $tid, 'double') == 'double';
  }
  switch ($form_state['values']['action']) {
    case 'subscribe':
      simplenews_subscribe_user($form_state['values']['mail'], $tid, $confirm, 'website');
      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, 'website');
      if ($confirm) {
        drupal_set_message(t('You will receive a confirmation email shortly containing further instructions on how to cancel your subscription.'));
      }
      else {
        drupal_set_message(t('You have been unsubscribed.'));
      }
      break;
  }
}