You are here

function simplenews_validate in Simplenews 5

Implementation of hook_validate().

File

./simplenews.module, line 341

Code

function simplenews_validate($node) {
  global $valid_mails;
  if ($node->send == 1) {
    if (!isset($node->taxonomy)) {
      $names = node_get_types('names', $node);
      form_set_error('', t('You should select content type %content_type in !newsletter_vocabulary before you can send this newsletter.', array(
        '%content_type' => $names[$node->type],
        '!newsletter_vocabulary' => l(t('Newsletter vocabulary'), 'admin/content/taxonomy/edit/vocabulary/' . variable_get('simplenews_vid', '')),
      )));
    }
    elseif (!simplenews_validate_taxonomy($node->taxonomy)) {
      form_set_error('taxonomy', t('You should select a newsletter before you can send this newsletter.'));
    }
  }
  elseif ($node->send == 2) {
    if (variable_get('simplenews_test_address_override', 0)) {
      $mails = explode(',', $node->test_address);
    }
    else {
      $mails = explode(',', variable_get('simplenews_test_address', ''));
    }
    foreach ($mails as $mail) {
      $mail = trim($mail);
      if ($mail == '') {
        form_set_error('', t('Cannot send test newsletter: no valid test e-mail address specified.'));
      }
      elseif (!valid_email_address($mail)) {
        form_set_error('', t('Cannot send test newsletter to %mail: e-mail address invalid.', array(
          '%mail' => $mail,
        )));
      }
      else {
        $valid_mails[] = $mail;
      }
    }
  }
}