1 user.pages.inc user_autocomplete($string = '')

Menu callback; retrieve a JSON object containing autocomplete suggestions for existing users.

File

core/modules/user/user.pages.inc, line 10
User page callback file for the user module.

Code

function user_autocomplete($string = '') {
  $matches = array();
  if ($string) {
    $result = db_select('users')->fields('users', array('name'))->condition('name', db_like($string) . '%', 'LIKE')->range(0, 10)->execute();
    foreach ($result as $user) {
      $matches[$user->name] = check_plain($user->name);
    }
  }

  // Displayed as JSON by delivery callback backdrop_json_deliver().
  return $matches;
}