dsgwii4867 2009-11-05 20:47
浏览 61
已采纳

Drupal自定义节点表单

I want to create an input form for registered user, separated from admin's content creation form. Each submission will create multiple node. To illustrate the case, I will use content type Project, and Review.

Project: Title, Description, Owner, Rating.

Review: Title, Reviewer, Project, Difficulty

I have setup the content types along with their fields using CCK modules. I want to create an input form to be displayed for registered members (non-admin). Its field includes Project Name, Description, Owner, Rating, Review, Difficulty.

When the form is submitted, Project Name, Description, Owner, and Rating value goes into new Project node, where the rest goes into new Review node.

Another customization that I would like to do is for Rating and Difficulty input field to use star rating input.

What would be the best way to accomplish this? Should I create custom module and custom form (Can anyone point me how to do this)? Or is there any modules I could use?

Thanks

  • 写回答

3条回答 默认 最新

  • dongleiqiao4906 2009-11-06 08:22
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?