Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
By userofdrupal on
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
If all you want to do is
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.
I'll create a module if I
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
Also this lullabot article
Also this lullabot article talks about the option of changing forms either through theming or modules:
(http://www.lullabot.com/articles/modifying-forms-5-and-6)
So anyone know how to do this with themes?
Theme comment form
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 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
Thanks for your reply! I
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.
(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?
use exactly the same
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 '
';
}
Also I want to remove the
Also I want to remove the information about comment format at the bottom of the comment form. E.g.:
How can I do this?
Snippet
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:
Thanks for your reply. What
Thanks for your reply. What I ended up doing was this:
Just to add a little more
Just to add a little more followup, my original code below did nothing:
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.