Altering drupal comments in hook_comment op = validate (drupal 5)
Added Tue, 17/02/2009 - 22:12
One of those little Drupal annoyances this, there is now easy way to alter a comment (using hook_comment) before the comment is written to the DB. Hook comment is invoked during the validation phase, with $op set to "validate", and the comment array is passed by reference - but unfortunately any changes made to the comment are not passed on to the comment save function.
A quick and slightly dirty way around this is to make use of the global $form_values array and manipulate the comment directly in there - this little example will set an empty comment title to "(No subject)" rather than allowing the comment to default to using the first X characters of the comment itself.
function yourmodule_comment(&$a1, $op){
if ($op=='validate'){
global $form_values;
if (trim($a1['subject']) == '') {
$form_values['subject'] = t('(No subject)');
}
}
}
Bookmark/Search this post with:

Delicious
Digg
Reddit
Technorati


Hi People
How are you doing?
Hi,
Thanks for that really useful, I'm a Drupal developer and managed to implement this nicely.
Thanks,
Ed
as far as i can tell, if i do a browser refresh of a form - hit the Reload button in the browser, and resend the form submission - $form_state['storage'] is erased.
Have your say ...