使用form_alter以注释形式添加新的消息字段,想知道它是否正确完成

问题描述

| 我想知道它是否正确完成,并希望提出改进建议。 我刚刚在注释表单中添加了此警告:   →评论写作说明:用不正确的英语写的评论,   语法不正确,使用简短形式,   使用印地语单词等-这些评论   将被删除。 请在此网页实施中向下滚动。 这是form_alter模块代码
<?PHP

function change_comment_form_form_alter(&$form,&$form_state,$form_id)
{

if( $form_id===\"comment_form\" 
)
  {

  $form[\'warning\'] = array(
  \'#type\' => \'item\',\'#title\' => t(\'&rarr;Comment Writing Instructions\'),\'#value\' => \'Comments written in incorrect English,improper grammar,using short forms,using hindi words etc - those comments will be deleted.\',\'#weight\' => -15,);


  }

}
    

解决方法

        这是更改形式的正确方法。 但是,如果在注释文本区域之前或之后显示文本,将更加易于使用。您还应该隐藏“输入格式”字段集。 在您的代码中,只要可以翻译句子,就应将所有书面句子括在t()中。重新编写代码的示例:
 \'#title\' => \'&rarr;\' . t(\'Comment Writing Instructions\'),\'#value\' => t(\'Comments written in incorrect English,improper grammar,using short forms,using Hindi words etc - those comments will be deleted.\'),
编辑:Drupal FAPI或Forms API在这里有一个文档齐全的页面:http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html/6 您应该看看所有可用的#type。