I've successfully printed a comment form on a views-built page using a PHP Views field (as found in this question). The form doesn't submit right away though - instead of submitting, the comment "save" button redirects to the "comment/reply/[nid]" page with blank values.

Comment form print code:

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

Are there extra details that should be added to the $comment object before or during the drupal_get_form() or render() calls?


Try next:

// ...
$comment->nid = $row->nid;
$form = drupal_get_form('comment_form', $comment);
$form['#redirect'] = 'CHANGE_VIEWSPAGE_HERE?page=' . (int)$_GET['page'];
print render($form);
| improve this answer | |
  • Nice work. What's the difference between setting ?page and ?destination ? – emc Feb 6 '12 at 7:17
  • 1
    ?page mean that after submission comment, you form return to views with certain page number (if it's pagered), so user will not move across pages again after submission... – Nikit Feb 6 '12 at 8:16

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