You are here

function simplenews_subscriptions_account_form_submit in Simplenews 7

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

FAPI ACCOUNT subscription form_submit.

1 string reference to 'simplenews_subscriptions_account_form_submit'
simplenews_subscriptions_account_form in includes/simplenews.subscription.inc
FAPI ACCOUNT subscription form.

File

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

Code

function simplenews_subscriptions_account_form_submit($form, &$form_state) {
  global $user;
  $account = $form['#user'];

  // 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) {
    if ($checked) {
      simplenews_subscribe_user($account->mail, $tid, FALSE, 'website');
    }
    else {
      simplenews_unsubscribe_user($account->mail, $tid, FALSE, 'website');
    }
  }
  if ($user->uid == $account->uid) {
    drupal_set_message(t('Your newsletter subscriptions have been updated.'));
  }
  else {
    drupal_set_message(t('The newsletter subscriptions for user %account have been updated.', array(
      '%account' => $account->name,
    )));
  }
}