How to disable a field or make it readonly in Drupal 7

前端 未结 2 804
轻奢々
轻奢々 2021-01-05 14:32

I am trying to disable couple of fields and make them readonly via hook_page_alter(). I was able to do check if user is viewing the page edit section (the form edit)

相关标签:
2条回答
  • 2021-01-05 15:22

    Like it said in the docs

    You can use attributes :

    $form['#attributes'] = array('disabled' => TRUE);
    
    0 讨论(0)
  • 2021-01-05 15:29

    It works for text fields^

    $form['field_secured_title']['und']['0']['value']['#attributes']['disabled'] = TRUE;
    
    0 讨论(0)
提交回复
热议问题