You are here

function logintoboggan_user_edit_validate in LoginToboggan 7

Same name and namespace in other branches
  1. 5 logintoboggan.module \logintoboggan_user_edit_validate()
  2. 6 logintoboggan.module \logintoboggan_user_edit_validate()

Custom validation function for user edit form

1 string reference to 'logintoboggan_user_edit_validate'
logintoboggan_form_user_profile_form_alter in ./logintoboggan.module
Implement hook_form_user_profile_form_alter().

File

./logintoboggan.module, line 579
LoginToboggan module

Code

function logintoboggan_user_edit_validate($form, &$form_state) {
  $account = $form['#user'];
  $edit = $form_state['values'];

  // If login with mail is enabled...
  if (variable_get('logintoboggan_login_with_email', 0)) {
    $uid = isset($account->uid) ? $account->uid : 0;

    // Check that no user is using this name for their email address.
    if (isset($edit['name']) && db_query("SELECT uid FROM {users} WHERE LOWER(mail) = LOWER(:mail) AND uid <> :uid", array(
      ':mail' => trim($edit['name']),
      ':uid' => $uid,
    ))
      ->fetchField()) {
      form_set_error('name', t('This name has already been taken by another user.'));
    }

    // Check that no user is using this email address for their name.
    if (isset($edit['mail']) && db_query("SELECT uid FROM {users} WHERE LOWER(name) = LOWER(:name) AND uid <> :uid", array(
      ':name' => trim($edit['mail']),
      ':uid' => $uid,
    ))
      ->fetchField()) {
      form_set_error('mail', t('This e-mail has already been taken by another user.'));
    }
  }
  if (!empty($edit['pass'])) {

    // if we're changing the password, validate it
    $pass_err = logintoboggan_validate_pass($edit['pass']);
    if ($pass_err) {
      form_set_error('pass', $pass_err);
    }
  }
}