Hello everybody.
I have interesting problem. I need to create form with auto complete text field.
I have the data table in database with next fields | nid | login|
And when i type login nothing happens.
here my code:
function my_search(){
global $user;
$form['name'] =array(
'#type' => 'textfield',
'#title'=>'User login',
'#size'=> 9,
'#autocomplete_path' => 'my/autocomplete/',
);
$form['submit'] = array( '#type' => 'submit', '#value' => t('Search') );
return $form;
}
function my_menu(....){
$items[] = array('path' => 'my/autocomplete',
'title' => t('Autocomplete '),
'callback' => 'my_autocomplete',
'access' => user_access('access content'),
'type' => MENU_CALLBACK);
return $items;
}
function my_autocomplete($string = '') {
global $user;
$uid = $user->uid;
$regexp = '%(?:^|,\ *)("(?>[^"]*)(?>""[^"]* )*"|(?: [^",]*))%x';
preg_match_all($regexp, $string, $matches);
$array = $matches[1];
// Fetch last tag
$last_string = trim(array_pop($array));
if ($last_string != '') {
$result = db_query_range("SELECT t.login, t.nid FROM {my_table} t WHERE t.uid = %d AND LOWER(t.login) LIKE LOWER('%%%s%%')", $uid, $last_string, 0, 10);
$prefix = count($array) ? implode(', ', $array) .', ' : '';
$matches = array();
while ($tag = db_fetch_object($result)) {
$n = $tag->login;
// Commas and quotes in terms are special cases, so encode 'em.
if (strpos($tag->login, ',') !== FALSE || strpos($tag->login, '"') !== FALSE) {
$n = '"'. str_replace('"', '""', $tag->login) .'"';
}
$matches[$prefix . $n] = check_plain($tag->login);
}
print drupal_to_js($matches);
exit();
}
}
How i can do it?
And what wrong with the code?
Comments
Impossible
Impossible!
Does anybody know about it?
Did you clear out the menu
Did you clear out the menu cache?
cache
Yep. No result.
How it should work?
Is any tutorials in drupal? or something like API FORM reference?
Try out this tutorial
http://drupal.org/node/147029
Thanks.
I was born in USSR