5

我想为注册用户创建一个输入表单,与管理员的内容创建表单分开。每次提交都会创建多个节点。为了说明这种情况,我将使用内容类型ProjectReview。

项目标题描述所有者评级

审查:标题,审稿人,项目,难度

我已经使用 CCK 模块设置了内容类型及其字段。我想创建一个为注册成员(非管理员)显示的输入表单。其字段包括项目名称描述所有者评级审查难度

提交表单后,Project NameDescriptionOwnerRating值进入新的Project节点,其余的进入新的Review节点。

我想做的另一个自定义是让RatingDifficulty输入字段使用star rating input

实现这一目标的最佳方法是什么?我应该创建自定义模块和自定义表单(谁能指出我该怎么做)?或者有什么我可以使用的模块吗?

谢谢

4

3 回答 3

8

There are several ways to do this:

  1. Do everything from scratch: This is what theunravelers suggestion (+1) boils down to - build the form yourself, add your own validation and submit handlers and on submit, build two node objects and save them. You'll have full control/flexibility, but it is quite some work and you need to have a good understanding of Drupals inner workings to get it right.

  2. 'Overload' one of your content types with the fields needed by the other and tweak the 'overloaded' content types submit (and partially edit/display) logic to create the other content type from the additional fields, while hiding them on the 'overloaded' one on display and edit. You can find an article describing this approach here. This is a considerably easier approach than #1, but I'd consider it to be a bit 'hackish', because of the content type definition vs. display mismatch.

  3. A less 'hackish' variation of #2 would be to set up your content types normally and just manipulate the edit and submit process via hook_form_alter(). You'd do more or less the same as with approach #2, but instead of 'overloading' one node with the additional fields upfront, you'd just inject them into the edit form directly on hook_form_alter (either from scratch or by loading the edit form of the other node in the background and copying the relevant field definitions from that). On form submission, you remove those additional fields while using them to build your other node. This requires a bit more work and knowledge than #2, but should be a bit more stable and easier to adjust/maintain than that, as you do not have to deal with a content type definition vs. display mismatch.

Also, you did not specify how you want to deal with editing of existing nodes - I'd suggest adding a nodereference to one of the nodes to keep track of their association. That way, you could also add the logic to edit both nodes from one form, as well as synchronized deletion, if desired.

于 2009-11-06T08:22:18.507 回答
4

这对我来说听起来像是一个定制的工作。您可以在模块中使用Form API来制作表单。查看几乎任何其他模块,以了解有关 Form API 工作原理的示例。然后,您需要从这些字段的所有值创建一个 $node 对象,并使用node_submit()node_save()来实际创建不同的节点。

我建议也许查看 Webform 模块以使用 Form API 并劫持提交过程以使其创建这两种节点类型。

于 2009-11-05T21:01:45.133 回答
2

选项#3,使用其中一种年轻的解决方案来创建可以指向不存在的节点的 CCK 节点引用字段,并在提交时创建它。

Node Reference Create看起来像是这些项目中更稳定的项目之一。

节点引用自动创建节点引用字段似乎对确定新节点中的值有更多的附加值。

这在构建模块之间的节点引用方面具有次要优势,您可以在渲染时使用它来集成节点,创建视图等等。

于 2009-11-07T17:52:54.597 回答