my project site has users with their full names (first last) as their usernames. I've been using autocomplete for the search function but it only retrieves entries that are written in the same manner, ie. first last. it won't work if i start typing the last name first. does anybody know how i can edit the default user_autocomplete so that it will work whether i type in the first or the last name when matching entries against the user database...

Comments

dries’s picture

You'll have to modify (yuck, sorry) the user.module. Search for the following line in the user_autocomplete function:

  $result = db_query_range("SELECT name FROM {users} WHERE LOWER(name) LIKE LOWER('%s%%')", $string, 0, 10);

and replace it with:

  $result = db_query_range("SELECT name FROM {users} WHERE LOWER(name) LIKE LOWER('%%%s%%')", $string, 0, 10); // added two %s to make username matching work properly
localhost’s picture

The extra %% didn't work. code stopped working. Any more ideas?

localhost’s picture

it works!

arjun.r’s picture

Rather than modifying the user.module, it's better to creat a custom module. and copy the autocomplete code. Then you can modify the search string as per requirement and just point the #autocomplete_path in your form to your new module.
Check it out: http://drupal.org/node/147029
Arjun