I tried to make an autocompleted text field following this tutorial.
I did the following:
In my form:
$items['juego'] = array('#type' => 'textfield', '#title'=>t('Game').$req,'#autocomplete_path' => 'juego/autocomplete/','#size'=>'20','#maxlength'=>'100'/*,"#required"=>True*/,'#default_value' =>variable_get('juego', ""),'#description' => t('Name of the game to compete in'));
In the menu hook:
$items[] = array('path' => 'juego/autocomplete', 'title' => t('game autocomplete'),
'callback' => 'juego_autocomplete', 'access' => user_access('access content'), 'type' => MENU_CALLBACK);
...And the handler function:
function juego_autocomplete($string) {
$matches = array();
$result = db_query_range("SELECT nombre FROM t_juegos WHERE LOWER(nombre) LIKE LOWER('%s%%')", $string, 0, 10);
while ($juego = db_fetch_object($result)) {
$matches[$juego->nombre] = check_plain($juego->nombre);
}
print drupal_to_js($matches);
exit();
}
The problem is that when I type something into the text field, the handler is called but no string is passed to it, so the autocomplete returns all the possible options and not just the ones that match what I've typed.