如何解决使用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(\'→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\' => \'→\' . 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。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。