You are here

function simplenews_subscriptions_page_form_submit in Simplenews 7

Same name and namespace in other branches
  1. 6.2 includes/simplenews.subscription.inc \simplenews_subscriptions_page_form_submit()
  2. 7.2 includes/simplenews.subscription.inc \simplenews_subscriptions_page_form_submit()

FAPI PAGE subscription form_submit.

2 string references to 'simplenews_subscriptions_page_form_submit'
simplenews_subscriptions_multi_block_form in includes/simplenews.subscription.inc
FAPI MULTI BLOCK subscription form.
simplenews_subscriptions_page_form in includes/simplenews.subscription.inc
FAPI PAGE subscription form.

File

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

Code

function simplenews_subscriptions_page_form_submit($form, &$form_state) {
  $mail = $form_state['values']['mail'];
  $account = simplenews_load_user_by_mail($mail);

  // Group confirmation mails as necessary and configured.
  simplenews_confirmation_combine(TRUE);
  switch ($form_state['values']['op']) {
    case t('Update'):

      // We first subscribe, then unsubscribe. This prevents deletion of subscriptions
      // when unsubscribed from the
      arsort($form_state['values']['newsletters'], SORT_NUMERIC);
      foreach ($form_state['values']['newsletters'] as $tid => $checked) {
        $confirm = simplenews_require_double_opt_in($tid, $account);
        if ($checked) {
          simplenews_subscribe_user($mail, $tid, $confirm, 'website');
        }
        else {
          simplenews_unsubscribe_user($mail, $tid, $confirm, 'website');
        }
      }
      if (simplenews_confirmation_send_combined()) {
        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('The newsletter subscriptions for %mail have been updated.', array(
          '%mail' => $form_state['values']['mail'],
        )));
      }
      break;
    case t('Subscribe'):
      foreach ($form_state['values']['newsletters'] as $tid => $checked) {
        if ($checked) {
          $confirm = simplenews_require_double_opt_in($tid, $account);
          simplenews_subscribe_user($mail, $tid, $confirm, 'website');
        }
      }
      if (simplenews_confirmation_send_combined()) {
        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('The newsletter subscriptions for %mail have been updated.', array(
          '%mail' => $form_state['values']['mail'],
        )));
      }
      break;
    case t('Unsubscribe'):
      foreach ($form_state['values']['newsletters'] as $tid => $checked) {
        if ($checked) {
          $confirm = simplenews_require_double_opt_in($tid, $account);
          simplenews_unsubscribe_user($mail, $tid, $confirm, 'website');
        }
      }
      if (simplenews_confirmation_send_combined()) {
        drupal_set_message(t('You will receive a confirmation e-mail shortly containing further instructions on how to cancel your subscription.'));
      }
      else {
        drupal_set_message(t('The newsletter subscriptions for %mail have been updated.', array(
          '%mail' => $form_state['values']['mail'],
        )));
      }
      break;
  }
}