You are here

function pet_validate_recipients in Previewable email templates 6

Same name and namespace in other branches
  1. 7 includes/pet.admin.inc \pet_validate_recipients()

Validate existence of a non-empty recipient list free of email errors.

1 call to pet_validate_recipients()
pet_user_form_validate in ./pet.admin.inc
Validate PET form.

File

./pet.admin.inc, line 515
Contains administrative pages for creating, editing, and deleting previewable email templates (PETs).

Code

function pet_validate_recipients($form_state, &$recipients) {
  $errors = array();
  $recipients = array();
  if ($form_state['storage']['recipient_callback']) {

    // Get recipients from callback
    $mails = pet_callback_recipients($form_state);
    if (!is_array($mails)) {
      $errors[] = t('There is no recipient callback defined for this template or it is not returning an array.');
      return $errors;
    }
  }
  else {

    // Get recipients from form field
    $mails = pet_parse_mails($form_state['values']['recipients']);
  }

  // Validate and build recipient array with uid on the fly
  foreach ($mails as $mail) {
    if (!valid_email_address($mail)) {
      $errors[] = t('Invalid email address found: %mail.', array(
        '%mail' => $mail,
      ));
    }
    else {
      $recipients[] = array(
        'mail' => $mail,
        'uid' => pet_lookup_uid($mail),
      );
    }
  }

  // Check for no recipients
  if (empty($errors) && count($recipients) < 1) {
    $errors[] = t('There are no recipients for this email.');
  }
  return $errors;
}