You are here

function og_invite_form_validate in Organic groups 6

Same name and namespace in other branches
  1. 5.8 og.module \og_invite_form_validate()
  2. 5 og.module \og_invite_form_validate()
  3. 5.2 og.module \og_invite_form_validate()
  4. 5.3 og.module \og_invite_form_validate()
  5. 5.7 og.module \og_invite_form_validate()
  6. 6.2 og.pages.inc \og_invite_form_validate()

File

./og.module, line 871

Code

function og_invite_form_validate($form, &$form_state) {
  global $user;
  $max = variable_get('og_email_max', 10);
  $mails = $form_state['values']['mails'];
  $mails = str_replace("\n", ',', $mails);
  $emails = explode(',', $mails);
  if (count($emails) > $max) {
    form_set_error('mails', t('You may not specify more than %max email addresses or usernames.', array(
      '%max' => $max,
    )));
  }
  elseif (in_array($user->mail, $emails)) {
    form_set_error('mails', t('You may not invite yourself - @self.', array(
      '@self' => $user->mail,
    )));
  }
  else {
    $valid_emails = array();
    $bad = array();
    foreach ($emails as $email) {
      $email = trim($email);
      if (empty($email)) {
        continue;
      }
      if (valid_email_address($email)) {
        $valid_emails[] = $email;
      }
      else {
        $account = user_load(array(
          'name' => check_plain($email),
        ));
        if ($account->mail) {
          $valid_emails[] = $account->mail;
        }
        else {
          $bad[] = $email;
        }
      }
    }
    if (count($bad)) {
      form_set_error('mails', t('Invalid email address or username: @value.', array(
        '@value' => implode(', ', $bad),
      )));
    }
    else {

      // Store valid e-mails so we don't have to go through that looping again on submit
      $form_state['valid_emails'] = $valid_emails;
    }
  }
}