「form_mods」と呼ばれるフォームを変更するための小さなモジュールを作成しました。私が変更しているフォームは「user_profile_form」です。「プロファイル」という追加フィールドのカテゴリを追加しました。「profile_state」と呼ばれる Drupal 管理者に選択フィールドを作成し、モジュールでキー => 状態の値リストを持つように変更しています。管理者としてログインしているが、匿名ユーザーがregister は空の状態選択フィールドを認識します。ここに権限の問題はありますか?フィールドに 'access' => user_access('access content') を追加しようとしましたが、うまくいきませんでした。これが私のコードです:
function form_mods_form_alter($form, $form_state, $form_id) {
switch ($form_id) {
## user_profile_form ###################################################################################
case 'user_profile_form': // This is our form ID.
//echo '###'.$form['_category']['#value'].'###';
if($form['_category']['#value'] == 'Profile'){
// Modify the states dropdown list
$states = load_states_list();
$form['Profile']['profile_state'] = array(
'#type' => 'select',
'#title' => t('State'),
'#options' => $states,
'#required' => TRUE,
'#default_value' => isset($form['Profile']['profile_state']['#default_value']) ? $form['Profile']['profile_state']['#default_value'] : '',
'#element_validate' => array('profile_state_validate')
);
}
####################################################################################
break;
}
}
function load_states_list() {
$states = array('' => '-- Select a state'); // add a default empty value
$results = db_query("SELECT * FROM {states_list} ORDER BY name ASC");
while ($state = db_fetch_array($results)) {
$states[$state['code']] = $state['name'];
}
return $states;
}
ありがとう