You are here

function mailchimp_unsubscribe_form_validate in Mailchimp 6

Same name and namespace in other branches
  1. 5.2 mailchimp.module \mailchimp_unsubscribe_form_validate()
  2. 5 mailchimp.module \mailchimp_unsubscribe_form_validate()
  3. 7 mailchimp.module \mailchimp_unsubscribe_form_validate()

File

./mailchimp.module, line 555
Mailchimp module.

Code

function mailchimp_unsubscribe_form_validate($form, &$form_state) {
  if (!$form_state['values']['EMAIL']) {
    form_set_error('EMAIL', t('Please enter your email address.'));
  }
  else {
    if ($q || ($q = _mailchimp_get_api_object())) {
      $subscribed = FALSE;
      foreach ((array) $q
        ->lists() as $list) {
        $subscribed = $subscribed || _mailchimp_is_subscribed($list['id'], $form_state['values']['EMAIL'], $q);
      }
      if (!$subscribed) {
        form_set_error('', t('That email address could not be found.'));
      }
    }
    else {
      form_set_error('', t('There was an error processing your request. Please try again later.'));
    }
  }
}