I'm looking for a good, standards friendly way to alter the default comments form, such that there is a disclaimer immediately below the "Reply" header. I only want this disclaimer to appear above the comments form itself, not meerly when viewing comments.
This thread ( Drupal: adding disclaimer text above the submit button in a webform ) partially answers what I want but I'm not sure about how to apply the solution specifically to the comments form.
I know that this could be a rank amateur question, but any and all help is appreciated. Thanks.
Edit: I've tried implementing hook_form_alter as suggested and have managed to get the disclaimer to appear within the form just fine. One problem: the first draft of my disclaimer seems to be trapped above the comment form when replying to a comment. Clearing the cache, resetting the theme registry (on every page load, thanks to devel module) all have no effect.
Reply to Comment:
[first version of disclaimer] // won't go away, ever
[comment form]
[current version of disclaimer] // this one is fine
[submit button]
Any help here would again be most appreciated.
Edit (redux): Implemented the template.php centric solution. It was able to work just fine without any of the external effects as described above. Still not sure about a solution to the above problem. Thanks everyone.
The comment form is a unique animal among Drupal forms in that it's not themeable by default, so the usual methods won't work without a little bit of extra help.
In short, you'll first need to register the form as themeable in your template.php file:
/**
* Implementation of hook_theme().
*/
function mytheme_theme(){
return array(
'comment_form' => array(
'arguments' => array('form' => NULL),
),
);
}
Next, you can add a theme function to drop in some additional elements to the form:
/**
* Theme the output of the comment_form.
*
* @param $form
* The form that is to be themed.
*/
function mytheme_comment_form($form) {
$form['new_element'] = array(
'#type' => 'markup',
'#title' => t('Disclaimer'),
'#value' => '<p>You have been disclaimed, sir!</p>',
'#weight' => -20 // Lighter elements float to the top of the form
);
return drupal_render($form);
}
An understanding of how the Forms API (http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html) works will help you through making these edits. But, if you're just adding some HTML it should be pretty easy.
Of course, be sure to rebuild your theme registry after you've added the theme function.