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条)

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法