在创建表单提交时,如何自动设置CCK节点引用字段的值 [英] How do I set the value for a CCK Node-reference field automatically when create form submits
问题描述
由于引用的节点始终是已知的,我不希望用户输入参考值,我想为他们幕后设置。我发现了很多关于这样做的线程,但是没有一个似乎不清楚或者实际上适用于我。
任何帮助将不胜感激。
注意: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_save($ node);
}
break;
}
}
这应该将值添加到节点并保存创建后。
http ://api.drupal.org/api/function/hook_nodeapi
注意:您将需要创建一个模块来促进此功能。您也可以尝试规则模块,但是,我不确定它会在没有自定义规则的情况下执行所需的操作。但是我知道上面的方法会奏效。
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.
Any help would be greatly appreciated.
Note: Drupal 6
You can try:
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屋!