I have attached a view which displays comments to basic page content type using EVA module. I've also implemented the following to have the "add comment" form displayed just above the comments list:
/**
* Implements hook_views_pre_build().
*/
function mymodule_views_pre_build(&$view) {
if ($view->name == 'page_comments') {
if ($node = menu_get_object()) {
$comment = new stdClass;
$comment->nid = $node->nid;
$form = drupal_get_form('comment_form', $comment);
$form['#redirect'] = current_path() . '?page=' . (int)$_GET['page'];
$header = drupal_render($form);
$view->add_item('default', 'header', 'views', 'area', array('content' => $header, 'format' => 'full_html'));
}
}
}
It should work like this:
- on page /node/12, which contains the node, comment list and the "add comment" form, the user enters new comment and submits
- the page reloads quickly
- the submitted comment appears in the comment list on the same page, together with another "add comment" form
What actually happens:
- as above
- user is redirected to page /comment/reply/12 which also contains the node, comment list and the "add comment" form
- however, the previously submitted comment is lost, it doesn't appear in the database or anywhere else
- the user can then again enter a comment and submit
- if he does so, he is redirected to page /node/12#comment-1561, which contains the node, comment list and the "add comment" form
- the second submitted comment is on the comment list
So there are two problems with my added form: comment is not submitted and there is redirection. What needs to be done to make it work the way it should?