You are here

function subuser_add_validate in Subuser 5

File

./subuser.module, line 157

Code

function subuser_add_validate($form_id, $form_values) {
  $edit = $form_values;

  // check duplicate user name
  if ($error = user_validate_name($edit['name'])) {
    form_set_error('name', $error);
  }
  else {
    if (is_object(user_load(array(
      'name' => $edit['name'],
    )))) {
      form_set_error('name', t('The name %name is already taken.', array(
        '%name' => $edit['name'],
      )));
    }
    else {
      if (drupal_is_denied('user', $edit['name'])) {
        form_set_error('name', t('The name %name has been denied access.', array(
          '%name' => $edit['name'],
        )));
      }
    }
  }

  // check duplicate email
  // Validate the e-mail address:
  if ($error = user_validate_mail($edit['mail'])) {
    form_set_error('mail', $error);
  }
  else {
    if (is_object(user_load(array(
      'mail' => $edit['mail'],
    )))) {
      form_set_error('mail', t('The e-mail address %email is already registered. ', array(
        '%email' => $edit['mail'],
        '@password' => url('user/password'),
      )));
    }
    else {
      if (drupal_is_denied('mail', $edit['mail'])) {
        form_set_error('mail', t('The e-mail address %email has been denied access.', array(
          '%email' => $edit['mail'],
        )));
      }
    }
  }
}