创建表单提交时如何自动设置CCK节点引用字段的值 [英] How do I set the value for a CCK Node-reference field automatically when create form submits

查看:21
本文介绍了创建表单提交时如何自动设置CCK节点引用字段的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个引用不同内容类型 (B) 的单个节点的内容类型 (A).可以使用创建此新节点 (A) 的用户的信息以编程方式确定引用的节点 (B)...每个用户只能创建引用内容类型 (B) 的单个节点,因此该单个节点将始终为从用户创建的内容类型 B 的节点引用.

I have a content type (A) that references a single node of a different content type (B). The node referenced (B) can be programmatically determined using the information for the user creating this new node (A)... Each user can only create a single node of the referenced content type (B), so this single node will always be referenced from nodes of content type B that the user creates.

因为引用的节点总是已知的,我不希望用户必须输入引用值,我想在幕后为他们设置.我找到了很多关于这样做的主题,但似乎没有一个明确或对我有用.

Because the referenced node is always known, I don't want the user to have to enter the reference value, I want to set it for them behind the scenes. I've found a number of threads about doing this, but none seem to be clear or actually work for me.

任何帮助将不胜感激.

注意:Drupal 6

Note: Drupal 6

推荐答案

你可以试试:

function mymodule_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
   switch ($op) {
      case 'insert':
         if ($node->type == 'type_a') {
            $node->field_of_reference[0]['nid'] = 'node reference value';
            node_save($node);
         } 
         break;
   }
}

这应该将值添加到节点并在创建后保存它.

This should add the value to the node and save it after it has been created.

http://api.drupal.org/api/function/hook_nodeapi

注意:您需要创建一个模块来促进此操作.您也可以尝试规则模块,但我不确定它是否会在没有自定义规则的情况下完成您的要求.但我知道上面的方法会奏效.

Note: You will need to create a module to facilitate this. You can also try the Rules module, though, I am not sure it will do what you ask without a custom rule. But I know the above method will work.

这篇关于创建表单提交时如何自动设置CCK节点引用字段的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆