In my module I'd like to allow admin/moderator to add some user specific settings e.g. user steve1 has to work between 8am and 3pm.
To make work easier for the admin I'd lke to use autocomplete field for choosing user.
Suggestions are made via user name, but to form, I need to pass uid instead of a name.
Is this possible via modyfinig my autocomplete code, or should I change provided name to uid during form_submit operation?
$matches = array();
$query = db_select('users', 'u');
$return = $query
->fields('u', array(
'uid',
'name'
))
->condition('u.name', '%' . db_like($string) . '%', 'LIKE')
->range(0, 10)
->execute();
foreach ($return as $row) {
$matches[$row->name] = check_plain($row->name);
}
// return for JS
drupal_json_output($matches);