You are here

function newsletter_subscribe_form_submit in Newsletter 7

Callback of newsletter subscription block.Degrades when js is off. Validates e-mail and sends user to next step.

1 string reference to 'newsletter_subscribe_form_submit'
newsletter_subscribe_form in ./newsletter.module
Loads up the form that is displayed to the newsletter block.

File

./newsletter.module, line 1388
Defines menu items for newsletter administration, permissions and basic drupal hooks.

Code

function newsletter_subscribe_form_submit($form, &$form_state) {
  $is_ajax = isset($form_state['input']['ajax_page_state']);
  if (isset($form_state['values']['logged-in'])) {
    global $user;
    $mail = $user->mail;
  }
  elseif (!isset($form_state['values']['logged-in'])) {
    $mail = $form_state['values']['email'] != t('user@example.com') ? $form_state['values']['email'] : '';
  }
  if (!valid_email_address($mail) || newsletter_is_subscribed($mail)) {
    $msg = t("This e-mail doesn't exist or you have already subscribed");
    return $is_ajax ? '<div id="newsletter-error">' . $msg . '</div>' : drupal_set_message($msg, 'warning');
  }
  $q = array(
    'destination' => '',
    'email' => $mail,
  );
  $url = url('newsletter/subscribe', array(
    'query' => $q,
  ));
  if ($is_ajax) {
    return "<script type='text/javascript'>\n        location.href='{$url}'\n      </script>";
  }
  drupal_goto('newsletter/subscribe', array(
    'query' => $q,
  ));
}