Skip to main content

Print the comment form with PHP

I'm trying to print a comment form with the following code.

<?php 
    print drupal_get_form('comment_form', array('nid' => $row->nid), t('Post new comment')); 
?>

All I get is the following error repeated 40 times:

Warning: Attempt to assign property of non-object in comment_form() (line 1845 of /home/admin/public_html/website.com/modules/comment/comment.module).`

The comment form is called from inside a PHP Views field. What is the proper way to add a comment for to a node in Drupal 7?

There are actually a lot more errors, most of which repeat at least once:

EntityMalformedException: Missing bundle property on entity of type comment. in entity_extract_ids() (line 7501 of /home/admin/public_html/website.com/includes/common.inc). Notice: Trying to get property of non-object in comment_form() (line 1854 of /home/admin/public_html/website.com/modules/comment/comment.module).

emc
  • 863
  • 1
  • 9
  • 22