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

dfdavis’s picture

Maybe this will work:
['field_test_text']['0']['value']['#attributes']['disabled'] = 'disabled';

jimbop’s picture

Just to tie this up... The following both work:

$form['field_name']['#type'] = 'hidden';
$form['field_name']['#access'] = FALSE;
yched’s picture

Status: Active » Fixed

#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')

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

kenorb’s picture

Status: Closed (fixed) » Closed (duplicate)