Hello,

I created several custom profile fields.

I'd like to have each custom profile field for authenticated user to not be editable except from administrator role, I don't want the authenticated user to modify it after it's registration process.

Example: a custom profile field called "company" has been created, then I would like the user to enter it's pertaining info (on the dregistration process) and afterwards when he has registered and is an authenticated user, have that custom profile field be editable only by an allowed specific role via permissions (say the administrator role), I don't want the authenticated user to edit it by going into his/her personal user profile and edit it (/user/xxx/edit).

It would be nice to be able to assign permission of editing own custom profile fields at the role level, that is allow/deny some roles to be able to edit or not their own custom profile fields, and of course user/1 should have access to edit all users custom profile fields

Can someone please explain how to achieve this ?

Comments

grigori’s picture

did you check Permissions / something like 'edit own profile' ?

vr_mex’s picture

grigori:

That permission you have posted does not exist in Drupal 6.9

meet.h.thakkar’s picture

I am also facing the same (but more complex) problem

but I want that users can not edit the particular category's fields in profile

1v1337 7hakkar

RG’s picture

A simple solution, but it could work.
Try to make your own module with a hook_form_alter() function, like this :

function mymodule_form_alter($form_id, $form_state, &$form) 
{
	switch($form_id)
	{			
		case 'user_edit' :
			global $user;
			if ($user->uid != 1) 
			{
				unset($form['account']['myfield']); // user can't modify or even see this field
				/* 
				 * if it doesn't work, you can also make the field hidden, 
				 * and assign its the old value... It works with mine, even if it's a little ugly
				 */
			}
		break;
	}
}
brei9000’s picture

RG, this didn't work for me. I have a category titled "Sponsorship Information" and in that category two fields called "profile_sponsor_company" and "profile_sponsorship_you_are_requesting." The first is a text field and the second is a drop down select.

Would that change the syntax? I tried using Devel to find the variables I need, but I didn't see the $form reference.

Any help is very appreciated.

Here is my custom module:

<?php
function restrictprofile_form_alter($form_id, $form_state, &$form)
{
    switch($form_id)
    {           
        case 'user_edit' :
            global $user;
            if ($user->uid != 1)
            {
			
				 unset($form['profile_sponsor_company']);
				 unset($form['profile_sponsorship_you_are_requesting']);
	
            }
        break;
    }
}
?>
xck’s picture

This function work for me (form_user_profile_form_alter) - function MYMODULE_form_user_profile_form_alter(&$form, &$form_state, $form_id)

alliax’s picture

I would be interested as well.

Ideally I'd like the field to be editable as long as something is entered. ie. if at registration time nothing is filled in, then the field can be edited later by the user. But as soon as it's value is different from empty, then it becomes uneditable/locked.

I'm pretty sure such a module must already exist, since the functionnality was available already in Drupal 4.. but how to find it that is my question..

WorldFallz’s picture

You might be able to do this with a combination of http://drupal.org/project/userprotect and http://drupal.org/project/rules, but it's probably easier to just use the snippet above and add an "if" to check if the field is empty and make it read only instead of unsetting it entirely.

edan7’s picture

Hi there,

Not sure if I am interpreting the intended end use exactly, however I recently had a similar problem. I found that a combination of the user protect module & http://drupal.org/project/profile_permission solved this issue.

edan.