Hi - I'm trying to theme cck text and taxonomy fields to readonly or disabled since I want the data visible but not editable for some users. This works fine for the title in any content type with:
$form['title']['#attributes'] = array('disabled' => 'disabled');
I think I must be missing something pretty obvious so apologies if I haven't found it in the forums (not for want of searching...) but attempts like the following haven't resulted in the field being disabled or set readonly. Any pointers? Thanks if so!
$form['field_test_text']['#attributes'] = array('disabled' => 'disabled');
or
$form['field_test_text']['value']['#attributes'] = array('disabled' => 'disabled');
Comments
Comment #1
dfdavis commentedMaybe this will work:
['field_test_text']['0']['value']['#attributes']['disabled'] = 'disabled';
Comment #2
jimbop commentedJust to tie this up... The following both work:
Comment #3
yched commented#disabled is an attribute for input elements
$form['field_test_text'] and $form['field_test_text'][0] are just structure wrappers, not actual form elements.
In cck forms, the actual input element is found somewhere like :
$form['field_test_text'][0]['value']
(depends on the field type)
#access or #type, OTOH, are generic FAPI properties, so setting them at the level $form['field_test_text'] works
(not exactly the same effect, though : 'hidden' vs 'visible but not editable')
Comment #4
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #5
kenorb commented#336355: Unable to add '#attributes' or use '#disabled' = true via hook_form_alter()
Comment #6
kenorb commented