hi,
How I can make a field of user profile read only for user.
So that only administrator can change it

Comments

newms’s picture

There is a module that does this I think. User Read Only or something like that. I can't seem to find it right now, but if you look in the modules page, you should find it.
newms

dldege’s picture

If you are creating profile fields with the profile module its just a check box under the visibility.

* Hidden profile field, only accessible by administrators, modules and themes.

This also means the user can't see it so it might be too read only for what you need.

If you wanted it to be viewable you would probably have to do this in the code by making the form item disabled. In that case you'd need a custom module and want to look at hook_profile_alter http://api.drupal.org/api/HEAD/function/hook_profile_alter and/or hook_form_alter http://api.drupal.org/api/HEAD/function/hook_form_alter to change the profile view and/or edit form.

dLd

sharique’s picture

I want to keep this field visible to use but read only.

Sharique Ahmed Farooqui

newms’s picture

Here's the link to the module I mentioned before:

http://drupal.org/project/user_readonly

newms

uncoolbob’s picture

This module does exactly what the OP (and I) wanted!

icelink’s picture

I need something similar. I have 3 profile list fields with numeric values attached. I want a 4th profile value (not numeric and will be a list of 7 or more choices) that is determined by a series of calculations of the first 3 values. The 4th profile will be read only or hidden so that it can only be changed by selecting different values for the the first 3 profiles. Is the hook_profile_alter what I'm looking for, or is there a series of modules that can accomplish this?

dldege’s picture

You probably want to hook into the profile form validation and set the values of your hidden fields there.

dLd

icelink’s picture

Thanks for your help. I did what you suggested and added a snippet that calculates the 4th profile value in the profile_save_profile function and it works great.