0
我已經使用module_form_alter鉤子構建了一個自定義註冊表單。我還用db_add_field將所需的新字段添加到數據庫中。現在我可以在用戶註冊/用戶配置文件編輯中將值添加到表格中,並且值也被存儲在數據庫中。但是我無法做的是獲取存儲在數據庫中的值在用戶配置文件中顯示編輯表單。有沒有一個鉤子來加載數據庫中的值來形成表單加載?或者還有其他方法嗎?Drupal自定義用戶註冊表格
function customUser_schema_alter(&$schema) {
// Add field to existing schema.
$schema['users']['fields']['detail'] = array(
'type' => 'varchar',
'length' => 100,
);
}
function customUser_install() {
$schema = drupal_get_schema('users');
db_add_field('users', 'detail', $schema['fields']['detail']);
}
function customUser_form_alter(&$form, &$form_state, $form_id) {
// check to see if the form is the user registration or user profile form
// if not then return and don’t do anything
if (!($form_id == 'user_register_form' || $form_id == 'user_profile_form')) {
return;
}
$form['account']['detail'] = array(
'#type' => 'textfield',
'#title' => t('Additional Detail'),
);
}
我所做的就是用hook_schema_alter修改用戶表的架構,然後添加兩個字段在模塊的hook_install使用db_add_field用戶表。在用戶個人資料頁面中,我可以看到用戶個人資料編輯/註冊頁面中的其他字段,這些值也在該字段中更新。我想要的和現在不起作用的是當顯示用戶配置文件編輯頁面時,從表格中獲取值的字段顯示在字段中。 –
您是否檢查您的值是否添加到{users}表中?如果他們在那裏。爲這些表單域設置一個「#default_value」=> $ account-> new_field'就足夠了。但是如果這不起作用,我需要查看代碼。 – tic2000
是的,這些值存在於{users}表中。我編輯了我的問題來添加代碼。 $賬戶變量究竟是什麼? –