我想知道它是否做得正确,并希望得到改进建议。
我刚刚在评论表单中添加了这个警告:
→评论撰写说明:
用不正确的英语撰写的评论,语法不当,使用简短形式,使用印地语等-那些评论将被删除。
请在此网页实现中向下滚动。
这是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
您应该查看所有可用的#类型。