Drupal 6 - 在视图中包含模块表单

发布于 2024-09-03 08:08:57 字数 391 浏览 6 评论 0原文

我正在利用“收藏夹”模块,以便让我的用户能够收藏他们喜欢的节点。

目前,我知道有一个块可用于列出收藏夹,以及该列表顶部的“添加到收藏夹”按钮。

我想要做的是生成包含按钮的表单,并将其包含在我生成的每个节点中。我已经将其破解并通过复制生成的表单并将其放入我的views-view--fields-.tpl.php模板中来快速工作,但是我相信这样做违背了Drupal背后的思想,并且可能手写的 form_id 和 form_token 引入了安全问题。

我尝试调用 get_form 函数,并将我在生成的表单代码中找到的 form_id 传递给它,但是我无法让 Drupal 识别它。从一些谷歌搜索中,我注意到以编程方式生成模块表单可能需要一个钩子,但我还没有找到任何好的例子。

创建此表单的最佳方法是什么?

I'm making use of the Favorites module, in order to allow my users to favorite nodes they like.

Currently, I know that there is a block available for listing out the favorites, along with the 'Add to favorites' button at the top of this list.

What I'd like to do is generate the form which includes the button, and include it within each node that I generate. I'd gotten it hacked up and quickly working by copying the generated form and placing it in my views-view--fields-.tpl.php template, however I believe that doing it this way goes against the thought behind Drupal, and probably introduces security issues with the form_id and form_token being hand-written.

I've attempted to call the get_form function, and have passed it the form_id that I found in the generated form code, however I can't get Drupal to recognize it. From some Googling I've noticed that generating module forms programmatically may require a hook, but I haven't been able to find any good examples of this.

What is the best way to go about creating this form?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深海少女心 2024-09-10 08:08:57

如果您已经有一个块,您可以将该块放在您的内容区域中并仅在某些页面上显示它吗?

我从未使用过收藏夹,但根据您的描述,我可能会使用标志模块。它使用 ajax,并且在节点视图中包含添加/取消标记链接非常容易。

对于编程方向,我也会查看 drupal_get_form。你在哪里注入该代码?

if you have a block already, can you put the block in your content region and only show it on certain pages?

I've never used Favorites, but from your description, I would probably use the flag module instead. It uses ajax, and it's really easy to include an add/un-flag link in the node view.

For a programmatic direction, I would have looked at drupal_get_form, as well. Where are you injecting that code?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文