Drupal hook_form_alter : how to target only node/edit and NOT node/add. Aso,为什么 #disabled 不起作用?

标签 drupal hook-form-alter

我想在 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/

相关文章:

php - drupal 搜索 api solr 索引中缺少字段

php - 在 drupal 中使用 hook_form_alter 设置 webform 组件值

forms - 如何在 Drupal 中隐藏用户编辑表单上的某些字段?

drupal - 使用选项卡创建 drupal 6 模块

php - 如何添加要在 drupal 中最后加载的 css?

php - Drupal 8 - 以编程方式禁用或启用主导航上的链接

Drupal Facebook 连接功能

validation - Drupal 7 - 尝试向所有节点编辑表单添加自定义验证

drupal - 为什么我不能将字段移动到 Drupal 表单中的字段集中 - 无法获取当前值