0

I have enabled the anonymous comment setting. And its E-mail form appears as shown below.

Comment E-mail form

Now, I want to change the text "The content of this field is kept private and will not be shown publicly." to "E-mail address will not be shown publicly."

How can I change this programmatically.

For information the HTML part I have copied through fire-bug which is as below.

<div class="form-item form-type-textfield form-item-mail">
     <label for="edit-mail">E-mail <span class="form-required" title="This field is required.">*</span></label>
     <input id="edit-mail" name="mail" value="" size="30" maxlength="64" class="form-text required" type="text">
     <div class="description">The content of this field is kept private and will not be shown publicly.</div>
</div>
2

This value is defined in the comment_form function. More specifically, it is the description in this section:

  // Add author e-mail and homepage fields depending on the current user.
  $form['author']['mail'] = array(
    '#type' => 'textfield',
    '#title' => t('E-mail'),
    '#default_value' => $comment->mail,
    '#required' => (!$user->uid && $anonymous_contact == COMMENT_ANONYMOUS_MUST_CONTACT),
    '#maxlength' => 64,
    '#size' => 30,
    '#description' => t('The content of this field is kept private and will not be shown publicly.'),
    '#access' => $is_admin || (!$user->uid && $anonymous_contact != COMMENT_ANONYMOUS_MAYNOT_CONTACT),
  );

You could create a custom module and implement hook_form_FORM_ID_alter. Your custom module file would contain below lines in a .module file and a basic .info file.

<?php

function MODULENAME_form_comment_form_alter(&$form, &$form_state, $form_id) {
  $form['author']['mail']['#description'] = t('E-mail address will not be shown publicly.');
}

Alternatively there are some options for overriding strings outlined here: Drupal 6 & 7 - Change default strings (text) without using full translation system

2
  • Hi, Thanks for answer. Instead of creating module, can I just put this function in template.php? I just tried and it is working perfectly. Is this the right way to do? Or I will have to create module? Thanks again. – CodeNext Jun 16 '16 at 6:29
  • In Drupal there is a thin line between modules and themes. I guess it is save to leave it there. – Neograph734 Jun 16 '16 at 6:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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