1

I would like to disable some form elements within a Profile2 form in Drupal 7 (ie still visible but not editable). I figured using hook_form_alter would be the way to go but I can't figure out where I need to set the ['disabled'] field to true.

Here is the code that I have:

$fields = field_info_instances('profile2', 'student')
if ($fields) {
  foreach($fields as $field) {
    $field['#disabled'] = true; <- don't know what attribute to set here
  }
}

In Drupal 6 this seemed pretty straight forward but using dsm($field) is not helping me determine what field attributes need to be set. I have Googled this and looked at the Drupal 7 API and I am still lost.

I am hoping someone can help me out here.

Thanks.

3

In drupal 7. You can use the "field permissions" module + profile2 module.
In order to disable some fields for anonymous user, you just edit the fields with custom permissions.
You can see the demo of configuration page from here : http://drupal.org/files/images/field_permissions.jpg

Currently to disable some fields from profile2 for register form, I just set permissions that don't allow the anonymous user to see that fields.

  • Thanks for the answer. I will look into using that module. – user5013 Feb 6 '13 at 18:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.