Hello Team! I've noticed that if user hasn't permission to edit a field the value of this field will be reset on submit. For example administrator add something to this field. However normal user without permission to edit this field go to edit form and save it. This will reset protected field value.
This is caused by unset($form[$category][$key]) function because the field is not visible but profile module will insert empty value for this field. A possible solution of this is:

//unset($form[$category][$key]);
$form[$category][$key]['#type'] = 'value';
$form[$category][$key]['#value'] = isset($form[$category][$key]['#default_value']) ? $form[$category][$key]['#default_value'] : '';

Comments

sampeckham’s picture

Priority: Normal » Critical

Having the exact same problem. Each time a user edits available fields to them the restricted fields (unseen by the user) are wiped.

Will try the solution - is this editing the .module file?

Sam

CardinalFang’s picture

Thanks for the solution, it seems to work for me.

ilo’s picture

Status: Active » Closed (duplicate)

I'd say, this approach solves the problem, but still hides the field even if user is able to see it with edit permission, setting to disabled or as 'markup' when user has view permissions would be prefered.

Closing because of duplicate with a patch to solve and other related issues at once: #957188: Fixing permissions, reset and validation errors on protected fields