我正在嘗試爲特定角色類型usersname創建一個帶自動完成文本字段的表單。但它不起作用。雖然當我使用「用戶/自動完成」,這是例如在drupal.org它的工作給予默認路徑...#autocomplete_path不能在Drupal 6中工作
這是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);
}
什麼能是什麼原因?
我有問題,因爲我沒有通過參數值$字符串查詢,一旦我做了&列表。但它仍然不像masqurade那樣過濾......但是給出了所有的名字......不過我會嘗試使用drupal_to_js並查看會發生什麼...... – RajeevK