我创建了一个名为“form_mods”的用于更改表单的小模块。我正在更改的表单是“user_profile_form”。我为名为“个人资料”的额外字段添加了一个类别。我在 Drupal 管理员中创建了一个名为“profile_state”的选择字段,并在我的模块中将其更改为具有状态的键 => 值列表,并且当以管理员身份登录但匿名用户试图注册看到一个空的状态选择字段。这里有权限问题吗?我尝试将 '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;
}
谢谢