function user_autocomplete

You are here

7 user.pages.inc user_autocomplete($string = '')
4.7 user.module user_autocomplete($string)
5 user.module user_autocomplete($string = '')
6 user.pages.inc user_autocomplete($string = '')

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

3 string references to 'user_autocomplete'
drupal-6.bare.database.php in modules/simpletest/tests/upgrade/drupal-6.bare.database.php
Bare installation of Drupal 6.17, for test purposes.
drupal-6.filled.database.php in modules/simpletest/tests/upgrade/drupal-6.filled.database.php
Filled installation of Drupal 6.17, for test purposes.
user_menu in modules/user/user.module
Implements hook_menu().

File

modules/user/user.pages.inc, line 11
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);
    }
  }

  drupal_json_output($matches);
}