Hi,

On our drupal site the newest comment is on the top. I'd like to move the comment form above the existing comments.

Thanks

stafford

Comments

l8a’s picture

Go to ?q=admin/comment/configure - there you will find it.

"Viewing options" -> "Default display order:"
Date - newest first
Date - oldest first

stafford’s picture

Yes, that works. The newest comment is on the top. But I need the comment form (textbox) above the newest comment.

stafford’s picture

any other idea?

stafford’s picture

pls help somebody! :) our users need this feature :)

vm’s picture

cannot be done without hacking a core drupal module or creating a new module.

The settings are to use on new page, or same page. it is unnatual to have a comment posting field above comments. typically one would read the comments beofre posting, not post before reading.

It may be possible to override this at theme level. Something for you to look into to create this effect for yourself.

stafford’s picture

I got a tip yesterday:

I moved this line

if (user_access('post comments') && node_comment_mode($nid) == COMMENT_NODE_READ_WRITE && (variable_get('comment_form_location', COMMENT_FORM_SEPARATE_PAGE) == COMMENT_FORM_BELOW)) {
      $output .= comment_form(array('nid' => $nid), t('Post new comment'));
    }

under this line:

$output .= "<a id=\"comment\"></a>\n";

and it works.

jonathan_hunt’s picture

--- ../../../modules/comment/comment.module     2007-02-20 17:25:19.000000000 +1300
+++ comment/comment.module      2007-02-22 15:54:12.000000000 +1300
@@ -91,9 +91,14 @@
 define('COMMENT_FORM_SEPARATE_PAGE', 0);
 
 /**
+ * Comment form should be shown above list of comments.
+ */
+define('COMMENT_FORM_ABOVE', 1);
+
+/**
  * Comment form should be shown below post or list of comments.
  */
-define('COMMENT_FORM_BELOW', 1);
+define('COMMENT_FORM_BELOW', 2);
 
 /**
  * Comments for this node are disabled.
@@ -557,7 +562,7 @@
     '#type' => 'radios',
     '#title' => t('Location of comment submission form'),
     '#default_value' => variable_get('comment_form_location', COMMENT_FORM_SEPARATE_PAGE),
-    '#options' => array(t('Display on separate page'), t('Display below post or comments')),
+    '#options' => array(t('Display on separate page'), t('Display above comments'), t('Display below post or comments')),
   );
 
   return system_settings_form($form);
@@ -1009,6 +1014,11 @@
         $output .= drupal_get_form('comment_controls', $mode, $order, $comments_per_page);
       }
 
+      // If enabled, show new comment form.
+      if (user_access('post comments') && node_comment_mode($nid) == COMMENT_NODE_READ_WRITE && (variable_get('comment_form_location', COMMENT_FORM_SEPARATE_PAGE) == COMMENT_FORM_ABOVE)) {
+        $output .= comment_form_box(array('nid' => $nid), t('Post new comment'));
+      }
+
       $divs = 0;
       $last_depth = 0;
       drupal_add_css(drupal_get_path('module', 'comment') .'/comment.css');
spooky69’s picture

If I read this correctly, this patch allows you to set the comment form to show above or below the list of comments. I presume that if you set it to show above the comments and on a new page that you would then see the comment form followed by the comments after having clicked a link to add a comment?

Additionally, would it not be better to override this in the theme template (?) instead of modifying one of the core modules?

yakker’s picture

Not being comfy modifying core, I just thought I'd post a tentative CSS solution.

The comment form lives in a wrapper with class="box". On node pages, "box" lives inside the div with id="comments". To get the comment form above the first comment, just absolutely position #comments .box {} at top:0px, give it an explicit height, and then add a padding-top to #comments that is the same size as that height in order to push the first comment below the form you just positioned.

So your markup is something like:

<div id="comments">

  <comment></comment>
  <comment></comment> etc.

  <div class="box>
    <comment form></comment form>
  </div>

</div>

And your style is:

#comments {
   position: relative; /*required for the absolute positioning on "box" to work*/
   padding-top: 400px;
}

#comments .box {
   position: absolute;
   height: 400px;
   top: 0px;
}

Obviously, if you have styling or markup inside "box" that will cause the content to exceed your height, it will overlap the first comments in the comment list. Also, browsers with resizable textarea boxes will resize overtop of any other regular markup, as the absolute positioning takes it out of the flow (at least, I think that's the reason).

I'm not a seasoned CSS builder, so if anyone out there knows any situations (especially common ones) that will break this, please post!
:)

stanuku’s picture

Nice solution it works fine. Its cool :-)........ thank u

yakker’s picture

No probs - glad it works! (I can uncross my fingers)
;)

wanderingstan’s picture

Just agreeing that this is a funny limitation of drupal. Many users are now used to Facebook-wall-style commenting where the submission form is at the top, with the newest comments just below. This really needs to be added as an option in core.

lizhenry’s picture

The folks who built our site controlled this with a page and panels that build the node, its content, then the comment and comment form.

So, moving the comments and comment form around was a matter of figuring out which panel in admin/build/panels shows nodes and comments. Then editing the panel's content, and moving panes around with a drag and drop interface. (This after hours of trying to do it in the templates and figuring out how the page was rendering. It's only simple if you know it's there!)

I thought I'd mention it in case anyone else is dealing with a site built with Panels in a similar way. I didn't have to install the "move comment form above comments" module at all.

tomotomo’s picture

You can render comments manually easily to do this with:
print comment_form_box($edit) . comment_render($node);

Details: http://www.saigonist.com/content/drupal-add-comment-form-above-comments

My blog on Drupal/Vietnam: Saigonist
Twitter: @tomosaigon / @tomodrupal

Georgii’s picture

I added the following to the footer in a block

<script type="text/javascript">
$(function(){
  $('.box').prependTo('#comments');
});
</script>
alliax’s picture

@Georgii: this worked easily, thanks.

Georgii’s picture

Nice to hear that! :)

MakeOnlineShop’s picture

Module for comments forms above comments

Hello,

Does it mean that there is no module or any easy way to put the comment form above the comments ?

Thanks.

vm’s picture

a google search and an investment of 5 minutes located http://drupal.org/project/comment_form_above_comments

MakeOnlineShop’s picture

Nothing new since ? As this module is a bit old.

Thank you anyway.

vm’s picture

The age of this type of module has no bearing since it's a theme function and the apis in drupal 6 don't change. Realistically you don't "need" a contrib module to do this. It (the module) was created so that users wouldn't have to write any code.

govindtotla’s picture

I am facing the same issue. but just resolved it. I also tried with the module http://drupal.org/project/comment_form_above_comments but didn't get any solution. But just resolved this by editing the core module. What i did is :
in file /module/comment/comment.module edited a function named "comment render()"
Just changed the sequence of placing the comment form.

pianomansam’s picture

Editing core is dangerous and highly unrecommended. Please consider one of the other approaches given above.

zeezack’s picture

How does one render the comment form - above the comments

so how do you render the comment form and then render the comments for the node.

$edit = array('nid' => $node->nid);
print comment_form_box($edit) . comment_render($node);

Something like this worked for drupal 6, but no longer for drupal 7
vm’s picture

ervan.salin’s picture

You can override the comment-wrapper.tpl.php, copy it from modules/comment to yourTheme/templates directory.
And the place the render of the form above your rendered comments like so.

<div id="comments" class="<?php print $classes; ?>"<?php print $attributes; ?>>

  <!-- Add new comment form -->
  <?php if ($content['comment_form']): ?>
    <h2 class="title comment-form"><?php print t('Add new comment'); ?></h2>
    <?php print render($content['comment_form']); ?>
  <?php endif; ?>

  <!-- Render comments if exists -->
  <?php if ($content['comments'] && $node->type != 'forum'): ?>
    <?php print render($title_prefix); ?>
    <h2 class="title"><?php print t('Comments'); ?></h2>
    <?php print render($title_suffix); ?>
  <?php endif; ?>

  <?php print render($content['comments']); ?>

</div>
hockey2112’s picture

To move the comment field above the existing comments in Drupal 8/9:

  1. Copy field--comment.html.twig to your theme.
  2. Move the following code:
     

      {% if comment_form %}
        <h2 class='title comment-form__title'>{{ 'Add new comment'|t }}</h2>
        {{ comment_form }}
      {% endif %}

    above this code:

      {% if comments and not label_hidden %}
        {{ title_prefix }}
        <h2{{ title_attributes.addClass(title_classes) }}>{{ label }}</h2>
        {{ title_suffix }}
      {% endif %}

      {{ comments }}

  3. Clear cache.

vinaysamant’s picture

i m trying this in different ways.. but not working. Using Bootstrap5 theme with some customisations