我正在尝试为我在 drupal 中使用的表单设置自动完成功能,
我当前的代码如下所示:
function HOOK_form($form){
$form['keyword'] = array(
'#type' => 'textfield',
'#attributes' => array(
'title' => 'search field',
'label' => 'search field',
),
'#required' => TRUE,
'#autocomplete_path'=>'get_tax/autocomplete'
);
return $form;
}
function HOOK_menu(){
$menu = array(
'get_tax/autocomplete/%' => array(
'page callback' => 'tax_autocomplete_callback',
'page arguments' => array(2),
'type' => MENU_CALLBACK,
),
);
return $menu;
}
function tax_autocomplete_callback(){
$terms = array();
foreach(taxonomy_get_tree(5) as $tax){
$terms[$tax -> tid] = check_plain($tax -> name);
}
drupal_json_output($terms);
}
对我来说,这应该有效,但事实并非如此。
有任何想法吗?