2
votes

I want to disable a cck field inside a specific form in Drupal 6. I´ve created a new module full of alterations, using hook_form_alter. The form id is articulo_node_form. The field in question is text, I´ve checked and it can be disabeled.

I´ve tried this:

function modding_form_articulo_node_form_alter(&$form, &$form_state, $form_id) {
  $form['field_articulo_tipo']['#disabled'] = 1;
}

The field doesn´t disable at all, instead, it dissappears.

Anyway that happens when I try to create a new articulo node or when I try to edit that node. I want to target only node edits, I mean, the same form, but when it´s being edited.

What´s wrong with that code? THANKS FOR YOUR HELP!!

Rosamunda

1
Try $form['field_articulo_tipo']['#attributes']['disabled'] = 'disabled'; - Clive
Brilliant! THANKS CLIVE! Is there any way to set a comment as best reply? Because that did the trick! - Rosamunda
Or you could just post this as reply and I would mark it as the best :) - Rosamunda
@RosamunaRosamunda You're more than welcome! I'll put this in an answer, who knows it might help someone else in the future too :) - Clive

1 Answers

3
votes

I can't think of a reason why the code you've got wouldn't work but you can use code like this to 'force' the attribute to be displayed:

$form['field_articulo_tipo']['#attributes']['disabled'] = 'disabled';