5

In my current project I want to embedding comment form for individual item in views but I did not get any settings/ configurations for the same in view. I tried to override template for the same using

print drupal_get_form('comment_form', array('nid' => $nid)); 

code but I got an error, so please suggest my any idea or any module using that I can show comment form in views.

Error: The website encountered an unexpected error. Please try again later.

4

In Drupal 7, function comment_form() is expecting an object parameter instead of array. This code should work for you:

$comment = new stdClass;
$comment->nid = $nid;
$form = drupal_get_form('comment_form', $comment);
print render($form);
1

You can do that in the view itself,, When you create a node view for example you choose teaser .. then in the teaser settings check "Display comments"

This will show the comments with the field after each node entry

0

I added a Global: PHP field and inside it I put in the output code field the following snippet:

<?php
$comment_form = drupal_get_form('comment_node_NODETYPE_form', (object) array('nid' => $data->nid));
print drupal_render($comment_form);
?>
  • Hello. When you see duplicated questions, please flag as duplicates, and not duplicate answers. – Mołot Dec 10 '13 at 11:20
  • @Mołot It's not that the questions are duplicate, it's that my answer copes multiple questions I came across. – leymannx Dec 10 '13 at 11:23
  • So please try and add some personalization to it. If the other one does not ask for form, why there is drupal_get_form in your answer? – Mołot Dec 10 '13 at 11:25
  • @Mołot As an alternative approach... However. I marked them for deletion. – leymannx Dec 10 '13 at 11:46
  • There is some difference between the other solution and this one. The solution by @nikhil-m respects comment settings on node type settings page, e.g. that anonymous users should insert contact info. – Miloš Kroulík Apr 5 '16 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.