0

我正在尝试为我在 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);

 }

对我来说,这应该有效,但事实并非如此。

有任何想法吗?

4

1 回答 1

1

Inside your hook_menu implementation, try to get rid of % at the end of the path definition because it is not needed.

function HOOK_menu(){
   $menu = array(
       'get_tax/autocomplete' => array( // THE EDITED LINE.
       'page callback' => 'tax_autocomplete_callback',
       'page arguments' => array(2),
       'type' => MENU_CALLBACK,
       ),
    );

   return $menu;
 }

If it still does not work, kindly copy & paste the error message you see.

于 2013-09-12T08:53:44.747 回答