“添加另一个项目”以非 CCK Drupal 形式

发布于 2024-08-13 03:11:12 字数 188 浏览 4 评论 0原文

Drupal 的 CCK 具有一个方便的功能,即允许单个 CCK 字段通过“添加另一个项目”按钮接受多个值,从而在节点中生成数据数组。

我想知道是否有任何简单的方法可以将其调整为我将通过 drupal_get_form 调用的非 CCK 表单。我宁愿不必使用多步骤表单技术重新发明轮子。

有人做过这个吗?

CCK for Drupal has the handy feature of allowing a single CCK field to accept multiple values via a "add another item" button that results in an array of data in the node.

I'm wondering if there's any easy way of adapting this for a non-CCK form that I'd be calling by drupal_get_form. I'd rather not have to re-invent the wheel with multi-step form techniques.

Anyone done this?

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

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

发布评论

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

评论(3

☆獨立☆ 2024-08-20 03:11:12

如果他们包含一个更简化的示例,那就太好了,但是 Drupal 中的 AHAH 简介这篇关于使用 AHAH 添加动态表单元素的文章 应该涵盖几乎所有您需要的内容(不幸的是,是相当多的)。

CCK 执行此操作的方式(主要在 content.node_form.inc 中的 content_add_more_js() 中)有点复杂,因为它们需要满足不同字段类型的泛化,并添加一些额外的内容允许平滑的表格排序拖放功能的东西。因此,除非您需要后者,否则我宁愿不使用它作为示例,因为它会有点令人困惑;)

It would be nice if they had included a more reduced example, but this Introduction to AHAH in Drupal, along with this post on adding dynamic form elements using AHAH should cover pretty much all you need (which, unfortunately, is quite a bit).

The way CCK does this (mainly in content_add_more_js() in content.node_form.inc) is a bit more convoluted, as they need to cater for the generalization for different field types, as well as adding some extra stuff to allow for smooth tablesort Drag&Drop functionality. So unless you need the latter, I'd rather not use it as an example, as it gets a bit confusing ;)

檐上三寸雪 2024-08-20 03:11:12

只是一个答案的存根,抱歉。如果没有人能给你更好的答案并且我有时间,明天我会详细说明一下。

我相信该功能是通过将 drupal 行为(来自 Drupal 标准 js 库)附加到您正在考虑的领域来完成的。如果我错了,那么它只是一个“临时”jQuery 函数。

但这是最简单的部分! ;) 棘手的是,该功能是通过 AJAX 实现的,而不是简单地在客户端生成额外的表单字段。之所以如此,是因为表单 API 必须完全重新生成表单,否则在提交时,最初未发送到浏览器的其他字段将被简单地忽略(这是为了防止注入)。

至少有一点!抱歉说得这么简洁。

Just a stub of an answer, sorry. If nobody else will give you a better answer and I have time, tomorrow I will elaborate a bit more.

I believe that functionality is done by attaching a drupal behavior (from the Drupal standard js library) to the field you are considering. If I am wrong, then it is simply an "ad-hoc" jQuery function.

However that's the easy part! ;) The tricky one, is that the functionality is achieved through AJAX and not by simply generating an extra form field client-side. This is so because the form API must regenerate the form entirely, otherwise - on submission - additional fields that where not originally sent to the browser will be simply ignored (this is intended, in order to prevent injection).

HTH at least a bit! Sorry for being so concise.

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