Disable field on hook_form_alter I have a form that I want to render with a disabled field.

I've already tried:

$form_element['#node']-&gt;field_assoc_cnpj[0]['#attributes'] = array('disabled' =&gt; 'disabled');


And also to use it directly into the form array:

$form['#node']-&gt;field_assoc_cnpj[0]['#attributes'] = array('disabled' =&gt; 'disabled');


Nothing seems to work.

How can I do that?
In simple terms, CCK is yet another module that alters the forms. When your form_alter function is used, even if you disable the field, it will not work. That's because the CCK forms are built after those form alter functions.
Note that this limitation is only for Drupal 6. In Drupal 7, it should work with regular form_alter functions. 

I had to do this on a client site. This page from Drupal docs helped me a lot.

See Clive's answer. It's how we do it on regular forms. 
But don't forget that you always can use field permissions which is much more robust than form alters. 

Also, note that setting the field's disabled attribute means this field will not be submitted by browser. If you want to get the value back to your site, use read only attribute with some fancy css to make it look like disabled (browser will take care to not allow editing). Chuck Norris can hack the page using Firebug or something to change the content though.