Does anyone know how to rename the "save" comment button? I am trying to change it to "Post". I am using Drupal 7 and the Zen sub theme.

link|improve this question

feedback

5 Answers

up vote 6 down vote accepted

For Drupal 7, you need to create a custom module that implements hook_form_FORM_ID_alter() using code similar to the following one (replace "mymodule" with the short name of the module you are writing):

function mymodule_form_comment_form_alter(&$form, &$form_state) {
  $form['actions']['submit']['#value'] = t('Post');
}

comment_form() uses the following code, to define the form buttons:

  // 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'),

For Drupal 6, the code should be the following one:

function mymodule_form_comment_form_alter(&$form, &$form_state) {
  $form['submit']['#value'] = t('Post');
}

In Drupal 6, comment_form() defines the form buttons using the following code:

  // 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,
  );
link|improve this answer
thank you very much, i will try editing the code :) – Jasmine Ahmed Nov 12 '11 at 1:24
1  
Just to be sure my answer is clear: You don't have to edit the code used by Drupal; you need to create a custom module that implements hook_form_FORM_ID_alter(). – kiamlaluno Nov 12 '11 at 10:16
feedback

Have you tried the String Overrides module?

link|improve this answer
no i haven't. I will try using the module. thanks :) – Jasmine Ahmed Nov 11 '11 at 16:05
3  
This module will change "save" in all the places it is used, not just in comments. – kiamlaluno Nov 11 '11 at 16:17
feedback

No need for custom module or using the string overrides module. In your settings.php, around line 416, uncomment and modify the following using your overrides:

/**
String overrides:

To override specific strings on your site with or without enabling locale
module, add an entry to this list. This functionality allows you to change
 * a small number of your site's default English language interface strings.
 *
 * Remove the leading hash signs to enable.
 */
# $conf['locale_custom_strings_en'][''] = array(
#   'forum'      => 'Discussion board',
#   '@count min' => '@count minutes',
# );
link|improve this answer
3  
Same problem as with the String Override module. Everytime a module calls t("Save"), the override would get used, such as the node edit form and a bunch of other places in the admin. – MPD Nov 11 '11 at 21:37
feedback

I prefer using hook_form_alter vs String Overrides.

YOURMODULENAME_form_comment_form_alter(&$form, &$form_state) {
  $form['buttons']['submit']['#value'] = 'Submit Comment'; //Your text for the submit button goes here.
};
link|improve this answer
thanks guys, will try finding and changing the code :) – Jasmine Ahmed Nov 12 '11 at 1:21
feedback

For Drupal 6, the answers above suggesting using hook_form_alter will not work, although you'd think it would. Typically you'd do this like:

function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if ('comment_form' == $form_id) {
    $form['submit']['#value'] = t('Post');
  }
}

While this appears to work, and you'll see a button with text 'Post', in fact you'll find two problems:

  1. If your site is set up to force preview of comments before saving, you'll find that the 'Post' button is added to the initial comment form, where there should be only the 'Preview' button. This is easily fixed, though.
  2. Your new 'Post' button won't actually submit the form - D6 comment.module looks for the button value to do its logic, and if you change it to something other than 'Save' this breaks the submit logic.

To actually make this work you'd need to hide the button and use a custom form submit handler. If I do that I'll return here and post working code.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.