You are here

function simplenews_subscription_manager_form_submit in Simplenews 5

Same name and namespace in other branches
  1. 6 simplenews.subscription.inc \simplenews_subscription_manager_form_submit()

Forms API callback; submit handler for subscription form.

File

./simplenews.module, line 1028

Code

function simplenews_subscription_manager_form_submit($form_id, $form_values) {
  switch ($form_values['op']) {
    case t('Update'):
      foreach ($form_values['newsletters'] as $tid => $checked) {
        if ($checked) {
          simplenews_subscribe_user($form_values['mail'], $tid, FALSE);
        }
        else {
          simplenews_unsubscribe_user($form_values['mail'], $tid, FALSE);
        }
      }
      drupal_set_message(t('The newsletter subscriptions for %mail have been updated.', array(
        '%mail' => $form_values['mail'],
      )));
      break;
    case t('Subscribe'):
      foreach ($form_values['newsletters'] as $tid => $checked) {
        if ($checked) {
          simplenews_subscribe_user($form_values['mail'], $tid);
        }
      }
      drupal_set_message(t('You will receive a confirmation e-mail shortly containing further instructions on how to complete your subscription.'));
      break;
    case t('Unsubscribe'):
      foreach ($form_values['newsletters'] as $tid => $checked) {
        if ($checked) {
          simplenews_unsubscribe_user($form_values['mail'], $tid);
        }
      }
      drupal_set_message(t('You will receive a confirmation e-mail shortly containing further instructions on how to complete the unsubscription process.'));
      break;
  }

  // Return to home page unless we set the destination back to the admin page.
  return '';
}