在任何页面中呈现评论表单

Bet*_*iga 2 forms comments drupal-7

我想知道如何在任何页面中呈现特定节点的注释表单(例如用户配置文件).我尝试使用drupal_get_form,但它显示错误.

drupal_get_form('mytype_node_form', array('nid' => $nid));
Run Code Online (Sandbox Code Playgroud)

欢迎解决方案和线索:)

小智 6

首先,您应该使用评论表单的正确ID:'comment_form'而不是'mytype_node_form'.

代码

drupal_get_form('comment_form', array('nid' => $nid));
Run Code Online (Sandbox Code Playgroud)

曾经在Drupal 6中为我工作.在Drupal 7中,函数comment_form()期望一个对象参数而不是数组.此代码应该适合您:

$comment = new stdClass;
$comment->nid = $nid;
$form = drupal_get_form('comment_form', $comment);
Run Code Online (Sandbox Code Playgroud)