5

I have a blog with comments and I need to change the "Your name" field to something different and make it a required field.

Can I do this from hook_form_comment_form_alter() hook in template.php or in a comments template?

8

You can do it in a hook_form_alter() function like you suggest:

function MYMODULE_form_comment_form_alter(&$form, &$form_state, $form_id) {
  $label = t('New label');
  if (isset($form['author']['_author'])) {
    $form['author']['_author']['#title'] = $label;
  }
  else {
    $form['author']['name']['#title'] = $label;
  }
}

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.