Skip to main content
  • Guides & Documentation

Knowledgebase

Featured articles, how-to guides and quick tips.

Change Comment Form Submit Button Text Value in Drupal 8

By default, Drupal 8 labels the submit button on comment forms as "Save". This is darn-right terrible for user experience, because users seldom want to "save" a comment on a node (or elsewhere). More typically, a user wishes to "post" their comment, or some other variation, such as "send" or "submit".

These alternative labels make total sense to users, but "save" is a surefire way to put them off.

Drupal 8 doesn't make it very easy to "rename" the Submit button on comment forms, or rather change the value of the submission button.

We'll have to dive into your theme's theme.theme file in order to modify this behavior using a form alter hook.

In your theme's theme.theme file, you'll need to add the following:

function THEME_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  if($form_id == 'comment_comment_form') {
    $form['actions']['submit']['#value'] = t('Post it');
  }
}

There are two parts to this code snippet that you'll need to modify for your specific purposes. They're highlighted in bold above.

Firstly, you'll need to ensure that the hook name (form_alter) is preceded by your theme's machine name (e.g. if your theme is named bartik, the hook would be bartik_form_alter).

Beyond this, you must ensure that the form_id you're targeting aligns with the ID for the comment form that you're aiming to alter.

If using Drupal's default comment type, you should be good to stick with comment_comment_form, but if you're using a custom Comment Type (using Drupal 8's new comment type structure), you'll need to ensure that you're entering the appropriate form_id here so that the correct comment form is targeted.

For instance, if your theme's machine name is bartik, and your comment form's ID is "comment_review_form", your hook should look exactly like this:

function bartik_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  if($form_id == 'comment_review_form') {
    $form['actions']['submit']['#value'] = t('Post it');
  }
}

Of course, you can also change the text string "Post it" to whatever you wish to replace Drupal's default "Save" value for the submission button.

Don't forget that you'll need to clear the Drupal cache after any changes are made to your theme.theme file.