I have a use case where I'm adding a comment to a node but not on a node page. When the comment is submitted everything works as it should, except that the comment isn't associated with an nid. So on page reload it's no longer there.
I tracked the problem down to the comment_form_alter in the module:
function ajax_comments_form_comment_form_alter(&$form, $form_state) {
$node = menu_get_object();
if (!isset($node) && arg(0) == 'ajax_comments') {
$node = node_load(arg(2));
}
In the case where the ajax comments is on a node page, then menu_get_object() should work. But when it's not then $node won't be set at all. Since the comment form already has an nid value this should be used as a fallback.
I've attached a small patch that should fix the issue.
| Comment | File | Size | Author |
|---|---|---|---|
| comment_form_nid.patch | 493 bytes | hadsie |
Comments
Comment #1
neochief commentedGood point, thanks! Commited.