I have a view page on which I have rendered the comment form for each node in the field using the code below:
$comment = new stdClass;
$comment->nid = $n->nid;
$form = drupal_get_form('comment_form', $comment);
print render($form);
All my forms are printing fine, but the issue is that when I enter a message on message field and click submit, it redirect me to node page with comment form at browser top and my message is lost. If I type and click save here, my message saves without an issue.
I altered the form, added a custom_submit_handler as follows:
$form['#submit'][] = 'mymodule_custom_submit';
and defined it as:
function sparx_custom_submit($form, &$form_state) {
if(isset($form_state['custom_redirect_path'])) {
$form_state['redirect'] = $form_state['custom_redirect_path'];
}
}
Now the problem I am facing is that each time I try the comment is getting added to the top-most node, not to any other node.
Any suggestions please