我已经使用 module_form_alter 钩子构建了一个自定义注册表单。我还使用 db_add_field 将所需的新字段添加到数据库中。现在我可以在用户注册/用户配置文件编辑中将值添加到表中,并且这些值也存储在数据库中。但我无法做的是获取存储在数据库中的值在用户配置文件编辑表单中显示。是否有一个挂钩可以将数据库中的值加载到表单加载中?或者还有其他方法吗?
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'),
);
}