Answers:
如果要在自定义模块中执行此操作
my_module_form_user_profile_form_alter(&$form, &$form_state) {
// Since it is on registration form, field might be reqruied.
$form['your_field']['#required'] = FALSE;
$form['your_field']['#access'] = FALSE;
}
my_module_form_user_register_form_alter,不会my_module_form_user_profile_form_alter。
将此代码放在自定义模块中,该字段将能够显示新内容,但将无法对其进行编辑。
if ($form_id == 'YOUR_FORM_ID') {
//dsm($form);
// for user form use '#user' instead of '#node' and uid instead of nid
if (isset($form['#node']) && isset($form['#node']->nid)){
// Prevent editing a field once the node has been created
// hiding the field entirely on the edit form.
$form['field_name']['#access'] = FALSE;
// disable update field on the edit form (gray color).
$form['field_name']['#disabled'] = TRUE;
}
}