You are here

function simplenews_block_form_submit in Simplenews 5

Same name and namespace in other branches
  1. 6.2 includes/simplenews.subscription.inc \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()

Forms API callback; handles block form (un)subscribe submissions.

File

./simplenews.module, line 1130

Code

function simplenews_block_form_submit($form_id, $form_values) {
  global $user;
  $account = _simplenews_user_load($form_values['mail']);

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