Create multiple CCK nodes with single custom form in Drupal

元气小坏坏 提交于 2019-12-05 21:39:02

why not just use hook_nodeapi to handle the node creation for certain content types.

just set up a test condition to see if $node->type = 'foo', and then run a function to create two nodes or however many, using the values from the predefined fields. you can even set hook_nodeapi to only run when the $op is almost ready to insert the node into the database, thus ensuring the object has been run through appropriate validation before being passed on to the new nodes that need to be created.

http://api.drupal.org/api/function/hook_nodeapi/6 this page has a list of all available operations for the $op variable and what they do.

I hope that helps

If the 2nd type bar needs only one or two additional inputs (fields) from the user, I would go with your approach one.

But given your clarification it seems that foo and bar are sufficiently different and complex, so your approach two seems more reasonable.

Concatenate both forms into one and hide the bar fields that you want to populate from the foo fields (or node, after you created it). In the forms validate and submit functions, you'll have to separate the forms again so that you can call the standard validation/submit handlers for both separately.

I have not done this yet, so I'm not sure how well this will play with the cck functionality, but I would expect it to work reasonably well to give it a try.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!