user_edit_validate

Versions
4.6
user_edit_validate($uid, &$edit)
4.7 – 5
user_edit_validate($form_id, $form_values)
6
user_edit_validate($form, &$form_state)

Code

modules/user.module, line 1084

<?php
function user_edit_validate($uid, &$edit) {
  // Validate the username:
  if ($error = user_validate_name($edit['name'])) {
    form_set_error('name', $error);
  }
  else if (db_num_rows(db_query("SELECT uid FROM {users} WHERE uid != %d AND LOWER(name) = LOWER('%s')", $uid, $edit['name'])) > 0) {
    form_set_error('name', t('The name %name is already taken.', array('%name' => theme('placeholder', $edit['name']))));
  }
  else if (user_deny('user', $edit['name'])) {
    form_set_error('name', t('The name %name has been denied access.', array('%name' => theme('placeholder', $edit['name']))));
  }

  // Validate the e-mail address:
  if ($error = user_validate_mail($edit['mail'])) {
    form_set_error('mail', $error);
  }
  else if (db_num_rows(db_query("SELECT uid FROM {users} WHERE uid != %d AND LOWER(mail) = LOWER('%s')", $uid, $edit['mail'])) > 0) {
    form_set_error('mail', t('The e-mail address %email is already taken.', array('%email' => theme('placeholder', $edit['mail']))));
  }
  else if (user_deny('mail', $edit['mail'])) {
    form_set_error('mail', t('The e-mail address %email has been denied access.', array('%email' => theme('placeholder', $edit['mail']))));
  }

  // Validate the user roles:
  if (user_access('administer users')) {
    if (!$edit['roles']) {
      form_set_error('roles', t('You must select at least one role.'));
      $edit['roles'] = array();
    }
    else {
      // Before form submission, $edit['roles'] contains ('role id' => 'role name') tuples.
      // After form submission, $edit['roles'] contains ('number' => 'role id') tuples.  We
      // flip the array to always have the role id's in the keys.
      $edit['roles'] = array_flip($edit['roles']);
    }
  }

  // If required, validate the uploaded picture.
  if ($file = file_check_upload('picture')) {
    $user = user_load(array('uid' => $uid));
    user_validate_picture($file, $edit, $user);
  }
  // Delete picture if requested, and if no replacement picture was given.
  else if ($edit['picture_delete']) {
    $user = user_load(array('uid' => $uid));
    if ($user->picture && file_exists($user->picture)) {
      file_delete($user->picture);
    }
    $edit['picture'] = '';
  }

  // If required, check that proposed passwords match.  If so, add the new password to $edit.
  if ($edit['pass1']) {
    $edit['pass1'] = trim($edit['pass1']);
    $edit['pass2'] = trim($edit['pass2']);
    if ($edit['pass1'] == $edit['pass2']) {
      $edit['pass'] = $edit['pass1'];
    }
    else {
      form_set_error('pass2', t('The specified passwords do not match.'));
    }
  }
  unset($edit['pass1'], $edit['pass2']);

  return $edit;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.