【问题标题】:Drupal form autocomplete from taxonomy来自分类的 Drupal 表单自动完成
【发布时间】:2013-09-10 09:42:33
【问题描述】:

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

 }

对我来说这应该有效,但它没有。

有什么想法吗?

【问题讨论】:

    标签: php drupal drupal-7 drupal-forms


    【解决方案1】:

    在您的hook_menu 实现中,尝试在路径定义的末尾去掉%,因为它不是必需的。

    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;
     }
    

    如果还是不行,请复制粘贴你看到的错误信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-02
      • 1970-01-01
      • 1970-01-01
      • 2012-06-07
      相关资源
      最近更新 更多