0

I am using following code to render node comment form in a block:

$comment_form = drupal_get_form('comment_node_<node_type>_form', (object) array('nid' => $nid));
print drupal_render($comment_form);

It is working fine.

Now I need to check if a user has already commented on the node. If the user has not commented than I will show him/her this comment add form.

But in case, the user has already placed a comment for the node, I want to show him/her the edit form for his/her comment, where he/she can make changes and save thus updating the existing comment instead of saving new.

Any suggestions?

1 Answer 1

0

I found a solution for this case, sharing so that anyone who need similar solution can use it.

Anyone who has similar issue can use the solution below:

<?php       
    $comment = comment_load($comment_id); // $comment_id = cid of comment whose edit form need to be open

    module_load_include('inc', 'comment', 'comment.pages');
    $form = drupal_get_form('comment_form', $comment); 

    return drupal_render($form);
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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