问题标签 [hook-form-alter]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
272 浏览

drupal - hook_form_alter changes array, but is not rendering in contact form

I use hook_form_contact_site_form_alter to alter the Conact Form. Everyting works fine when I change the array, for example:

dpm($form); shows me this:

enter image description here

So, thats perfect

... but nothing renders! Its still the good old default contact form: enter image description here

I was thinking, that maybe another hook overrides mine, or that I have to tell Drupal to rebuild the form. I haven't found anything usefuls in the API Reference yet.

Maybe somebody else had the same problem, or knows a good method to debug?

Thanks in Advance

btw. I had the contact_forms module installed, but uninstalled it again, maybe this is related.

0 投票
1 回答
72 浏览

php - 从 drupal 6 迁移到 drupal 7 form_alter hook 会引发错误 - 注意:未定义的索引:sport_utils_form_alter() 中的按钮

我正在从升级Drupal 6Drupal 7. 我在更新后启用了这个模块。

这是我的功能:

它在这一行抛出一个错误:

我不知道是否需要$form['buttons']用 Drupal 7 中的其他东西替换。

有什么建议么?

0 投票
1 回答
1211 浏览

drupal - 从节点添加表单中删除一个 drupal 选择列表选项

drupal可以从节点添加表单中删除选择列表选项,但将保留在编辑表单上,使用hook_form_alter.

提前致谢

0 投票
1 回答
127 浏览

arrays - 如何使用 page_arguments 将 hook_menu() 中的键控数组传递到 page_callback?

我已经实现了一个 hook_menu() 并调用了一个带有 page_callback 的函数。

我可以使用函数 bla_form($var) 定义在那里传递参数。当我回电时,return drupal_get_form('bla_node_form', $new_node, $project_id)我的 $var in $form_state['args'][1].

如果我通过了array(4),我会得到$form_state['args'][1].

如果我通过了array('project_id' => 4),我会得到$form_state['args'][1]['project_id'].

我想得到$form_state['args']['project_id'].

例子:

作为一种解决方法:如果我不能这样做:我如何确定我是否阅读了 $form_state['args'] 我正在使用正确的元素来获取我的论点(而不是其他一些)?

谢谢

0 投票
1 回答
888 浏览

forms - 当在 hook_form_alter() 中对字段使用 ['#access'] 时,我丢失了 '$form field default value' 和 $form_state 输入

当使用 EntityReference 字段并在 hook_form_alter() 中使用 ['access'] 隐藏该字段时,提交表单后 $form_state 输入对于该字段为空。

我有字段 field_to_a ,它是内容类型 B 上的实体引用字段,它引用内容类型 A。

我正在使用 hook_form_alter() 在其中我使用类似的行$form['field_to_a']['#access'] = FALSE;并将此字段设置为某个值

当我在节点上按下提交按钮(我的保存按钮)时,添加:

  • 当我使用时$form['field_to_a']['#access'] = FALSE;:我失去了 $form_state['input']['field_to_a'] (不存在)和$form['field_to_a']['und'][0]['target_id']['#default_value'](空)并且我有 PHP 错误。
  • 当我使用 NOT 时$form['field_to_a']['#access'] = FALSE;:我有 $form_state['input']['field_to_a'] 正确并且节点被保存而没有任何错误。

当我使用任何其他字段时,我可以使用 ['#access'] = FALSE 并且不会丢失 $form_state 中该字段的输入。

这件事有什么解决方案或解决方法吗?这是错误还是正常行为?

谢谢

0 投票
2 回答
1652 浏览

validation - 如何在模块中的验证钩子之后运行drupal hook_form_alter

我最近制作了一个 drupal 7 模块,我想自定义 drupal 显示验证错误的方式。我想在弹出窗口中放置错误消息。我把弹出生成代码放在表单alter hook中。

但是我不能让 drupal hook_form_alter 在验证钩子之后运行。我试图清除表单缓存并尝试使用“#after_build”而不是表单更改挂钩,但它们都在验证之前运行。似乎验证是该过程中运行的最后一件事。我把我的代码放在下面,请帮助我。

非常感谢您提前。

0 投票
1 回答
653 浏览

drupal-7 - Drupal 7 - 无法从 node_presave 中的 form_alter 获取表单值

我在其中添加了一些自定义字段,form_alter但无法获取hook_node_presave. 我错过了什么还是应该使用其他形式的钩子来获取价值?

0 投票
1 回答
501 浏览

drupal-7 - 将另一组字段集合添加到 mymodule_form_alter 中的 $form

我正在研究自定义测验模块,我们有多项选择题。我们为问题及其选项创建了单独的字段集合。作者可以添加无限数量的问题及其答案。

在创建新的多项选择测验时,Drupal 会呈现一个带有一个选项的问题,但默认情况下,我们希望为一个问题呈现 2 个选项。我应该如何将一组字段集合添加到表单更改中的另一个字段集合,或者是否有任何字段集合配置?

我的场景:

  1. 问题(文本区域)
    1. 选项(文本区域)

我们希望它是:

  1. 问题(文本区域)
    1. 选项(文本区域)
    2. 选项(文本区域)

我使用下面的代码将 field_collection 添加到表单中,但是在提交表单时未提交值。在节点页面中,我看不到值。

0 投票
2 回答
183 浏览

button - 工作台 hook_form_alter 更改

我正在使用 Workbench 模块套件,并且对节点编辑表单进行了简单的更改。

我只是想将节点添加/编辑页面底部按钮上的标签更改为更适合我们目的的自定义标签。

在此处输入图像描述

上图显示了我尝试重新标记节点/添加页面上的一些按钮。使用 hook_form_alter,只能访问 Drupal 的原生按钮集——我可以将 PREVIEW 按钮编辑为 TESTING PREVIEW。

但是,我似乎找不到编辑工作台模块相关按钮的方法 - Send to moderationSave as draft

谁能提供有关如何访问这些额外按钮的建议?

0 投票
1 回答
35 浏览

theming - 如何在 Drupal 的搜索表单的提交按钮中添加一个额外的类?

我正在尝试向搜索表单的提交按钮添加一个额外的类。我正在尝试显示图标字体而不是单词 Search。这个按钮的标记和我添加的类是这样的

我已经通过修改 search.module 文件成功地从值字段中删除了单词 search。我找了一个参考。到“form-submit”类,但它不在该文件中。

我还在 template.php 文件中尝试了以下内容。

但这没有用!,在这件事上的任何帮助将不胜感激。