Insert some data in comment upon comment submit For some reason I cannot find answer to relatively simple question. How to insert some data (for example the "title" filed value) into comment body upon the comment submit. Finally I'd like to have in comment body something like this:


Node title (with some CSS markup) -
Comment body - 


Could you please advice the right way to do this?
Since you didn't say which version of Drupal are you using, I'll assume that you're talking about D7.

You need to use hook_comment_presave().

function YOUR_MODULE_comment_presave($comment) {
  // Do this only for new comments.
  if (!$comment-&gt;cid) {
    // This code will insert the subject as heading.
    $subject = '&lt;h2&gt;' . $comment-&gt;subject . '&lt;/h2&gt;';
    $comment_text = $comment-&gt;comment_body[LANGUAGE_NONE][0]['value'];
    // Set the value.
    $comment-&gt;comment_body[LANGUAGE_NONE][0]['value'] = $subject . $comment_text;
  }
}


However, do bear in mind that you will need to handle somehow editing existing comments as well.

Hope this helps.