Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

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);
share|improve this answer
    
Nice work. What's the difference between setting ?page and ?destination ? –  npc 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
add comment

protected by kiamlaluno Mar 4 '13 at 14:22

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

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.