【发布时间】:2010-12-12 20:29:44
【问题描述】:
我在同一个站点的不同路径上,我需要允许用户更改他/她在不同位置写入的节点上的字段内容。我有 nodeid 和字段名称,以及 id 等 np。
我不认为这太难,但是有教程或解释会很棒。
谢谢。
编辑:感谢 anschauung 的提问,所以澄清一下:
这是一个 CCK 文本区域。至于为什么,有一个中心节点类型,有许多链接节点参考节点。从任何引用中心节点的节点的编辑页面,它需要能够编辑和保存中心节点的字段。这就是我的用例。
再次感谢。
非常感谢 googletorp,非常感谢您的帮助。
这是我目前所拥有的:
第一步:
function update_main_field_menu() {
$items = array();
$items['update_main_field/%'] = array(
'title' => 'Update Main Field',
'page callback' => 'post_to_main_node',
'page arguments' => 1,
'type' => MENU_CALLBACK
);
return $items;
}
第二步:
function post_to_main_node(){
// Sorry, I'm totally lost. What do I put here?
}
你也提到了这个:
在 hook_form_alter 中, hook_nodeapi 或其他一些钩子 当节点形式为 生成。你应该调查 哪种情况最适合您。
如何生成节点表单?
第三步:
function modulename_form_mainct???_node_form_alter (&$form, &$form_state) {
// I'm not sure about which form I'm doing node form alter on. If I do it to the mainct, wouldn't that alter the regular edit page the user is viewing? I only want to load the js for the ajax submission. Is there a update_main_field node form?
drupal_add_js(drupal_get_path('module', 'modulename') ."/updateField.js");
}
第 2 步中的函数和第 3 步中获取节点形式之间还有什么关系?
第 4 步: 我想我主要了解,但由于其他事情我还不能测试它。 :)
我真的很想学习如何在 drupal 中做到这一点,但是如果你能稍微提高一下你的语言的愚蠢程度,那就太好了。 :D 再次感谢你。
再次编辑:
我昨天实际上尝试放置访问参数,但由于某种原因它不起作用。 :( 但现在确实如此!是的,你有魔法。
现在,当我像这样触发帖子时:
Drupal.behaviors.ajax_update_field = function (context) {
$("#button").click(function(){
var url = $("#edit-field-reference-0-nid-nid").val().replace(/.*?\[nid:(\d+)?]/ig, "$1");
url = "/update_main_field/"+url;
// The data is just some silly test thing
$.post(url, {data: $("#edit-field-reference-0-nid-nid-wrapper label").text()}, function(value) {
// Here you can write your js to handle a response to the user,
// or if something went wrong an error message.
// value = response data from drupal
alert(value);
});
});
}
我看到一个包含正确数据的 URL 帖子。哪个好。但没有回应。警报为空。
还有一个新的空白......已经创建了一些东西。里面什么都没有,但是当过滤节点时我可以在视图中看到它。它没有标题、任何字段等。只有发布日期。
我要更新的节点没有更新。
所以这让我认为第二步可能有些不正确。我有几个问题。
function post_to_main_node(){
// Is this sufficient to load the node? nid doesn't have to be set as an arg for the function?
$node = node_load($_POST['nid']);
// Is the field set like this? 'field_library' is the 'machine name' of the field. This is what's needed right?
$node->field_library = $_POST['data'];
node_save($node);
}
再次感谢您。
【问题讨论】:
-
能否提供更多细节?例如,您能否描述您正在更改的字段、在什么情况下以及为什么?解释可能会非常非常不同,具体取决于您是否正在更改 CCK 字段、核心字段等。
-
感谢 anschauung,我编辑了问题。
-
我想我理解了这个问题,但是 jQuery 是从哪里来的呢?
-
我以为你会使用 jQuery 来进行 ajax 提交,因为 Drupal 打包了它?
-
它不起作用,因为您只是复制了我的插图代码,而不是将其用作指南。通读我的答案并查找您使用的功能,您拥有所需的一切,只需付出一些努力,您就会弄清楚。