Drupal hook_form_alter: how to target only node/edit and NOT node/add. Aso, why #disabled doesn´t work?

StackOverflow https://stackoverflow.com/questions/9781076

  •  25-05-2021
  •  | 
  •  

Question

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

Was it helpful?

Solution

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';
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top