我正在尝试为特定角色类型用户名创建一个带有自动完成文本字段的表单。但它不起作用。虽然当我使用“用户/自动完成”,这是在 drupal.org 示例中给出的默认路径时,它可以工作......
这是 hook_menu ---
function scout_bucks_menu(){
$items = array();
$items['scouts/autocomplete'] = array(
'page callback' => 'scout_bucks_autocomplete',
'type' => MENU_CALLBACK,
'access arguments' => array('administer scout bucks'),
);
return $items;
}
表单的这个 id --
function scoutbucks_add_bucks_form(&$form_state){
$form = array();
$form['scout_name'] = array(
'#type' => 'textfield',
'#title' => t('Scout Name'),
'#maxlength' => 60,
'#autocomplete_path' => 'scouts/autocomplete',
'#reguired' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#title' => t('ADD BUCKS TO SCOUT PROFILE'),
'#prefix' => '<div class="submit-button-bucks">',
'#suffix' => '</div>',
);
return $form;
}
这是自动完成的功能---
function scout_bucks_autocomplete($string = '') {
$matches = array();
$userobj = db_fetch_object(db_query("SELECT users.name, users.uid FROM {users}, {users_roles} WHERE users.uid = users_roles.uid AND users_roles.rid = 7"));
while ($row = db_fetch_array($userobj)) {
$matches[$row['users.uid']] = $row['users.name'];
}
drupal_json($matches);
}
可能是什么原因?