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);
  • 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

protected by kiamlaluno Mar 4 '13 at 14:22

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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