I have 1 field on user registration page that should not be changed after account registration. It needs to be hidden or disabled. Which module can do this ?
You can try Field Permissions Module
Features
- Enable field permissions on any entity, not just nodes.
- Role-based field permissions allowing different viewing patterned based on what access the user has.
- Author-level permissions allow viewing and editing of fields based on who the entity owner is.
- Permissions for each field are not enabled by default. Instead, administrators can enable these permissions explicitly for the fields where this feature is needed.
-
How can it differentiate between user creation and edit when it's the same field? I'm not saying it can't, I genuinely would like to know how. And I guess OP would, too. – Mołot Sep 11 '15 at 11:06
-
It will be role based field permission, need to give permission only for anonymous(not sure will this condition works for the case). – Bipin K Sep 11 '15 at 11:47
If you want to do it in custom module
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;
}
-
-
2@Smalution You don't have to - for registration form it would be
my_module_form_user_register_form_alter
, notmy_module_form_user_profile_form_alter
. – Mołot Sep 11 '15 at 11:12 -
1hook is hook_form_FORM_ID_alter FORM_ID for registration and edit is diefferent – arpitr Sep 11 '15 at 11:12
-
Ok got it. I have checked when user register its form id "user-register-form" and when user edit its form id "user-profile-form" normally. – DRUPWAY Sep 11 '15 at 11:34
-
Try with this code:
function MODULENAME_form_alter(&$form_state, $form_id){
$form[$field]['#access'] = FALSE;
$form[$field]['#disabled'] = TRUE;
}
-
2
-
Make field visibility property for anonymous users only. So Value will be stored at time of registration. Then no one can access that field. Once you install field permission module, you will find this option to apply to only anonymous user only.
function module_form_alter(&$form_state, $form_id) {
if (isset($form['title'])) {
$form['title']['#required'] = FALSE;
$form['title']['#type'] = 'value';
}
}
Try using hook_form_alter
, see the example below:
function MODULENAME_form_alter(&$form_state, $form_id){
global $user;
//$form_id :: user detail edit form id
if($user->uid != 0 && $form_id == "required_form_id"){
//$field :: requied field name
$form[$field]['#access'] = FALSE;
}
}
place this code in a custom module, field will be able on new content but will be disabled to edit it.
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;
}
}