doujingjiao0015 2010-09-20 22:47 采纳率: 0%
浏览 88
已采纳

如何在评论表单上方添加免责声明?

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.

  • 写回答

2条回答 默认 最新

  • dongle2627 2010-09-21 01:35
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据