- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在寻找一种良好的、标准友好的方式来更改默认的评论表单,以便在“回复”标题的正下方有一个免责声明。我只希望此免责声明出现在评论表单上方,而不仅仅是在查看评论时出现。
这个线程 ( Drupal: adding disclaimer text above the submit button in a webform ) 部分回答了我想要的,但我不确定如何将解决方案专门应用于评论表单。
我知道这可能是一个业余爱好者的问题,但我们将不胜感激。谢谢。
编辑:我已经尝试按照建议实现 hook_form_alter 并设法让免责声明很好地出现在表单中。一个问题:在回复评论时,我的免责声明初稿似乎被困在评论表上方。清除缓存、重置主题注册表(在每次页面加载时,感谢 devel 模块)都没有效果。
Reply to Comment:
[first version of disclaimer] // won't go away, ever
[comment form]
[current version of disclaimer] // this one is fine
[submit button]
这里的任何帮助将再次受到高度赞赏。
编辑(还原):实现了以 template.php 为中心的解决方案。它能够在没有上述任何外部影响的情况下正常工作。仍然不确定上述问题的解决方案。谢谢大家。
最佳答案
评论表单是 Drupal 表单中的一个独特动物,因为它在默认情况下不可主题化,因此如果没有一点额外的帮助,通常的方法将无法工作。
简而言之,您首先需要在 template.php 文件中将表单注册为主题:
/**
* Implementation of hook_theme().
*/
function mytheme_theme(){
return array(
'comment_form' => array(
'arguments' => array('form' => NULL),
),
);
}
接下来,您可以添加一个主题函数,将一些额外的元素放入表单中:
/**
* 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);
}
了解 Forms API ( http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html) 的工作原理将有助于您完成这些编辑。但是,如果您只是添加一些 HTML,那应该很容易。
当然,添加主题功能后一定要重建主题注册表。
关于php - 如何在评论表上方添加免责声明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3756076/
我是一名优秀的程序员,十分优秀!