I'm using Drupal 6.x with my own zen sub-theme.

I want to change the text on the comment form that says "Post new comment" to "Write review". How can I do this?

By printing the $form variable with print_r() I can see that the text "Post new comment" is stored in $form['#parameters'][3]. So I wrote the following function in template.php

function mytheme_comment_form($form) {

$form['#parameters'][3] = 'Write review';
return drupal_render($form);
}

However, nothing changes. The form is exactly the same.

Comments

dnewkerk’s picture

If all you want to do is reword some text, you can use String overrides module, or even without a module, check the very bottom of your sites/default/settings.php file.
However, here's some info I put together on altering the comment form: http://drupal.org/node/368776 (it's about removing elements, but you can affect other aspects of it too). I may be mistaken, but I believe you cannot do this in template.php, only within a module.

userofdrupal’s picture

I'll create a module if I have to but it seems like overkill to create a module just to change a line of text. I was somewhat following this site which seems to suggest you can change the comment form through theming:

http://adaptivethemes.com/using-hook-theme-to-modify-drupal-forms

userofdrupal’s picture

Also this lullabot article talks about the option of changing forms either through theming or modules:

So there are two methods for altering form output in Drupal, one at the theme layer and the other through a custom module. Changes to the HTML can be accomplished with either method so most people will use the method they are more comfortable with already...

(http://www.lullabot.com/articles/modifying-forms-5-and-6)

So anyone know how to do this with themes?

andriy’s picture

hi

you can do it like this:

function phptemplate_comment_wrapper($content, $node) {
$content = str_replace(t('Post new comment'), t('Write review'), $content);
return '

'. $content .'

';
}

$content is HTML of your form, so we just replace unwanted string,
if you already have this function in your templates.php file, then just modify $content variable.

another way is to to mpdify box.tpl.php, but I think, the first solution will work for you

hope, it helped

userofdrupal’s picture

Thanks for your reply! I will look into this method. Before I came across your post I just recently figured out how to change the title by changing the box variables as you suggest.

function mytheme_preprocess_box(&$vars, $hook) {

  switch($vars['title']) {
   case 'Post new comment':
    $vars['title'] = t('Write a review');
  }
}

(Code improvements welcome. Specifically I couldn't figure how to know I'm in a comment as opposed to another kind of box like search results)

Anyway, on the comment form there is a textarea labeled "Comment" and I would like to rename that to "Review" as well. Any ideas?

andriy’s picture

use exactly the same approach:
$content = str_replace('' . t('Comment') . ':', '' . t('Review') . ':', $content);

I replace a bit of HTML, in order not to change every occurance of word "Comment" within $content;

function phptemplate_comment_wrapper($content, $node) {
$content = str_replace('' . t('Comment') . ':', '' . t('Review') . ':', $content);
return '

'. $content .'

';
}

userofdrupal’s picture

Also I want to remove the information about comment format at the bottom of the comment form. E.g.:

    * Web page addresses and e-mail addresses turn into links automatically.
    * Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
    * Lines and paragraphs break automatically.

More information about formatting options

How can I do this?

dnewkerk’s picture

This is my personal favorite snippet I've found to do this... reason being that is preserves the actual filter/tips page itself (there's a simpler method which you can use, but it breaks that page). If you are ok with breaking the page (e.g. not going to show it) then you could use the simpler method (search for the wording of that link and you'll find it). I'm also including an extra line (at the top) which customizes the link that leads to filter/tips (I wrapped it with a div for styling, renamed the link text, and caused it to open in a new window just in case... some people though just set this to return '' if you don't want it to show up. Put this in template.php:

function phptemplate_filter_tips_more_info() {
  // Note: in the future need to change this to a Javascript new window to make XHTML strict compliant. Ideally launch filter tips in a modal window/lightbox.
  return '<div id="formatting-tips-link">'. l(t('Formatting tips'), 'filter/tips', array('attributes' => array('target' => '_blank', 'title' => 'Opens in a new window'))) .'</div>';
}


/* Implementation of theme_filter_tips()
* Remove filter tips under text input fields without removing the 'more info' link or breaking the /filter/tips page.
* http://drupal.org/node/35122#comment-1022780
*/
function phptemplate_filter_tips($tips, $long = FALSE, $extra = '') {
  $output = '';

  if (arg(0) == 'filter' && arg(1) == 'tips') {  // check if we are on the dedicated filter/tips page

    $multiple = count($tips) > 1;
    if ($multiple) {
      $output = t('input formats') .':';
    }

    if (count($tips)) {
      if ($multiple) {
        $output .= '<ul>';
      }
      foreach ($tips as $name => $tiplist) {
        if ($multiple) {
          $output .= '<li>';
          $output .= '<strong>'. $name .'</strong>:<br />';
        }

        if (count($tiplist) > 0) {
          $output .= '<ul class="tips">';
          foreach ($tiplist as $tip) {
            $output .= '<li'. ($long ? ' id="filter-'. str_replace("/", "-", $tip['id']) .'">' : '>') . $tip['tip'] .'</li>';
          }
          $output .= '</ul>';
        }

        if ($multiple) {
          $output .= '</li>';
        }
      }
      if ($multiple) {
        $output .= '</ul>';
      }
    }

  }
  return $output;
}
userofdrupal’s picture

Thanks for your reply. What I ended up doing was this:

 function mytheme_theme(&$existing, $type, $theme, $path) {
  $hooks = zen_theme($existing, $type, $theme, $path);
  // Add your theme hooks like this:
  /*
  $hooks['hook_name_here'] = array( // Details go here );
  */

  $hooks['comment_form'] = array('arguments' => array('form' => array()),
                                 );
  return $hooks;
}

function mytheme_comment_form($form) {

     $form['comment_filter']['comment']['#title'] = "Review";
     // Erase the filter tips info
     $form['comment_filter']['format']['format']['guidelines']['#value'] = NULL; 

    $output = '';
    $output .= drupal_render($form);

    return $output;
}

userofdrupal’s picture

Just to add a little more followup, my original code below did nothing:

 function mytheme_comment_form($form) {

$form['#parameters'][3] = 'Write review';
return drupal_render($form);
} 

This is pure conjecture but I think the reason is that the comment form isn't responsible for the text I was trying to change. Rather it's the box that goes around the comment form that handles this and that is why I need to make the change in the box function. I'm not sure of the exact mechanics behind this, maybe the box function got it's own copy of the $form variable that did not include my changes??

And I'm guessing the reason the other changes to the "comment" textarea label and the filter tips did work is because they are handled by the comment form itself.