Change the content of a comment, how?
I want to be able to change the actual text of a comment, as it is being sent to the site. I know how to do it with nodes, but when I apply the same principles to comments, it fails.
Here's what I do with my nodes:
1) I hook into form_alter and add my own function to $form['#validate']
2) In that function, I have access to &$form_state. I use the content of $form_state['values']['body'] to work my regex magic and I finish by writing the modified text back into $form_state['values']['body']
The net result is exactly what I'm looking for: if you Preview the node, or Edit it later on, the text box (and Preview) contain the modified text instead of what the author originally typed.
(In case you're wondering, yes, there's a very good reason why a simple text filter isn't enough, but the details would lead us away from the issue at hand.)
Then I found out it doesn't work for comments.
I use the same form_alter hook. I call a separate function for validation. I can find the comment's text in $form_state, but no matter what I do, nothing I do ends up changing the text in the same way that I can with a node...
As far as I can tell, the text of the comment appears in 4 places in the $form_state:
$form_state['values']['comment']
$form_state['buttons']['submit'][0]['#post']['comment']
$form_state['buttons']['button'][0]['#post']['comment']
$form_state['clicked_button']['#post']['comment']
I set all of them to be the new text, I've checked and all those assignments happen correctly. As far as I can tell, when validation is done, the original text is nowhere to be found in $form_state.
Yet the preview is no different. None of the changes are applied.
What am I doing wrong? And please please don't tell me this simply isn't possible for comments...
