对于Drupal 7,您需要创建一个自定义模块,该模块hook_form_FORM_ID_alter()
使用类似于以下代码的代码来实现(将“ mymodule”替换为您正在编写的模块的简称):
function mymodule_form_comment_form_alter(&$form, &$form_state) {
if (isset($form['actions']['submit'])) {
$form['actions']['submit']['#value'] = t('Post');
}
}
comment_form()使用以下代码来定义表单按钮:
// Only show the save button if comment previews are optional or if we are
// already previewing the submission.
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#access' => ($comment->cid && user_access('administer comments')) || variable_get('comment_preview_' . $node->type, DRUPAL_OPTIONAL) != DRUPAL_REQUIRED || isset($form_state['comment_preview']),
'#weight' => 19,
);
$form['actions']['preview'] = array(
'#type' => 'submit',
'#value' => t('Preview'),
'#access' => (variable_get('comment_preview_' . $node->type, DRUPAL_OPTIONAL) != DRUPAL_DISABLED),
'#weight' => 20,
'#submit' => array('comment_form_build_preview'),
对于Drupal 6,代码应为以下代码:
function mymodule_form_comment_form_alter(&$form, &$form_state) {
if (isset($form['submit'])) {
$form['submit']['#value'] = t('Post');
}
}
我if (isset($form['submit'])) {}
之所以添加该部件,是因为在Drupal 6中,comment_form()
使用以下代码定义了表单按钮,而您尝试更改的按钮无法显示在表单中。
// Only show save button if preview is optional or if we are in preview mode.
// We show the save button in preview mode even if there are form errors so that
// optional form elements (e.g., captcha) can be updated in preview mode.
if (!form_get_errors() && ((variable_get('comment_preview_' . $node->type, COMMENT_PREVIEW_REQUIRED) == COMMENT_PREVIEW_OPTIONAL) || ($op == t('Preview')) || ($op == t('Save')))) {
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#weight' => 19,
);
}
$form['preview'] = array(
'#type' => 'button',
'#value' => t('Preview'),
'#weight' => 20,
);