gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 07:13:06 25 4
gpt4 key购买 nike

我正在寻找一种良好的、标准友好的方式来更改默认的评论表单,以便在“回复”标题的正下方有一个免责声明。我只希望此免责声明出现在评论表单上方,而不仅仅是在查看评论时出现。

这个线程 ( 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com