Drupal 7 Webform 用当前节点标题填充隐藏字段
我使用网络表单作为特定内容类型的所有页面上的块。表单全部相同,但在提交列表中我想知道用户正在看到哪个页面。我认为隐藏字段和默认值 %title
就可以做到这一点,但事实并非如此。我尝试了一堆其他令牌值,其中很多都有效,但它们都没有给我当前节点的标识符。
I'm using a webform as a block on all the pages from a specific content type. The form is the same in all, but on the list of submissions I want to know which page the user was seeing. I thought a hidden field, and a default value of %title
would do it, but it's not the case. I tried a bunch of other token values, and a lot of them do work, but none of them gives me an identifier of the current node.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为它不起作用的原因是因为 webform 令牌的
node
元素引用了 webform 本身的节点,而不是当前节点页面。我不知道为什么 webform 不使用内置的令牌系统,似乎错失了机会。看看 webform 模块,我认为完成此任务的最简单方法是编写一个定义单个表(两列,
nid
和url
)的快速自定义模块,然后实现hook_webform_submission_insert()
保存所有 Webform 的当前$_SERVER['REQUEST_URI']
。然后,您可以分别使用hook_webform_submission_load()
和hook_webform_submission_render_alter()
将 URL 数据重新附加到提交并将其显示到页面。您可以在模块中包含的
webform_hooks.php
文件中找到所有这些钩子,它们都有很好的文档记录。I think the reason it's not working is because the
node
element of the webform tokens refers to the node of the webform itself, not the current node page. Why webform doesn't use the in-built token system I have no idea, seems like a missed opportunity.Looking at the webform module I think the easiest way to get this done is to write a quick custom module defining a single table (two columns,
nid
andurl
) and then implementhook_webform_submission_insert()
to save the current$_SERVER['REQUEST_URI']
for all webforms. You can then usehook_webform_submission_load()
andhook_webform_submission_render_alter()
respectively to re-attach the URL data to the submission and display it to the page.You can find all of those hooks in the
webform_hooks.php
file included in the module, they're pretty well documented.