我想在 Drupal 6 中禁用特定表单内的 cck 字段。 我使用 hook_form_alter 创建了一个充满更改的新模块。 表单 ID 为 articulo_node_form。有问题的字段是文本,I´ve checked并且可以将其禁用。
我试过这个:
function modding_form_articulo_node_form_alter(&$form, &$form_state, $form_id) {
$form['field_articulo_tipo']['#disabled'] = 1;
}
该字段根本不会禁用,而是消失。
无论如何,当我尝试创建新的关节节点或尝试编辑该节点时,都会发生这种情况。 我只想针对节点编辑,我的意思是,相同的形式,但在编辑时。
这段代码有什么问题吗? 感谢您的帮助!!
罗莎蒙达
最佳答案
我想不出您的代码不起作用的原因,但您可以使用这样的代码来“强制”显示属性:
$form['field_articulo_tipo']['#attributes']['disabled'] = 'disabled';
关于Drupal hook_form_alter : how to target only node/edit and NOT node/add. Aso,为什么 #disabled 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9781076/