Drupal Add Comment Form Above Comments

Submitted by tomo on March 24, 2011 - 12:57am

Drupal 6 allows you to either display the comment form below saved comments or on a separate page. There's surprisingly no way to configure the form to appear above the comments. It's hard-coded at the bottom of comment_render to either append the form, or not at all.

There's a micro-module aptly titled 'Comment form above comments' which does the job but does so using string replaces on resulting html so it's not the ideal or elegant solution.

It turns out to be simple to get the same effect in code.

First, we need to "configure" the form to appear on a separate page, but only because we're going to manually show it. You can ensure this configuration with the line:

variable_set('comment_form_location_'.$node->type, COMMENT_FORM_SEPARATE_PAGE);

You could even variable_get and re-variable_set after printing the form if you really wanted to.

Next, output the following where you want to display comments, whether in a PHP code block or node template:

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

Another recent discovery was that the comment form is hard-coded to redirect to /node after submitting. This hack, as a module, will get you back to the page you submitted from:

function noredirect_comment_form_submit(&$form, &$form_state) {
    $form_state['redirect'] = ltrim($form['#action'], '/');
}

function noredirect_form_alter(&$form, $form_state, $form_id) {
    if ($form_id == 'comment_form') {
       $form['#action'] = request_uri();
        $form['#submit'][] = 'noredirect_comment_form_submit';
    }
}

toultyDuth (not verified)

ges2ears farrah abraham sex video farrah abraham squirting kosnj4s9 http://farrahbackdoor.net mr0hnn36 nicki minaj video nicki minaj sex tape watch 1sbjbwe5 http://cherokeeroseranch.com

Donaldga (not verified)

|

Marat6404 (not verified)

Hello! =) Please help me in the matter.
In the Internet there are a lot of different portals with figures for the PC. All of these pictures is in the public domain. I can load any in all sizes. Let's say I open a small shop and create a portal that store. after taking one of these oboin , edit, cut a piece , such as the horizon, and upload to your web site .
Whether this act of copyright infringement? The idea is the image in the public domain and I take is only a fragment of the whole picture.I do not specifically extract profits out of the picture (that I do not sell the picture .) Have a right to make a claim for it ? If so, who? Will it be a violation of the law ?
Thanks in advance if anyone can help to understand this :)

Marat6404 (not verified)

Hello! =) Please help me in the matter.
In the Internet there are a lot of different portals with figures for the PC. All of these pictures is in the public domain. I can load any in all sizes. Let's say I open a small shop and create a portal that store. after taking one of these oboin , edit, cut a piece , such as the horizon, and upload to your web site .
Whether this act of copyright infringement? The idea is the image in the public domain and I take is only a fragment of the whole picture.I do not specifically extract profits out of the picture (that I do not sell the picture .) Have a right to make a claim for it ? If so, who? Will it be a violation of the law ?
Thanks in advance if anyone can help to understand this :)

NeahSheed (not verified)

good day fellas! this is an incredible community forum. My name is NeahSheed and I am researching experiences about FB inception.

Did anybody heard of this? For now, I've examined only good things about it, nevertheless I need to be aware of your current opinion about it.

Any sort of support will be appreciated.

Thanks a lot!
- NeahSheed

NeahSheed (not verified)

good day fellas! this is an incredible community forum. My name is NeahSheed and I am researching experiences about FB inception.

Did anybody heard of this? For now, I've examined only good things about it, nevertheless I need to be aware of your current opinion about it.

Any sort of support will be appreciated.

Thanks a lot!
- NeahSheed

JustinWells (not verified)

With the advent of the Internet in the 1990s, confidence in this new form of collecting and transferring information was an obvious pathway for banks to pursue. It gave bank customers what they never had before -- access to their money 24/7. Features have become more sophisticated and user friendly through the decade. Today's banks offer online banking services which allow users to conduct a variety of transactions - everything from account to account transfers and paying bills to applying for a loan or making an investment. Especially convenient, online banking allows users to instantly view their accounts, balance the books, and monitor spending. And with the use of personal finance programs, data can be easily imported making personal financial management easier than ever. Some banking programs even allow users to monitor all of their accounts at one site regardless if they are with their main bank or with another institution.

abbrakile (not verified)

Soon autumn, hurry to say goodbye to summer!).

Muthuraman (not verified)

Thanks a lot its save my time a lot :)

Anonymous (not verified)

I tried this in hook_nodeapi but it gives infinite loop when submitting a new comment, any idea why?

tomo

Which op value did you select on?

Tekriti Software (not verified)

Being in Drupal Development for a long time, I faced many situations where client asked for the same but couldn't deliver most of the time. Thanks for sharing the code. It will help me in many ways.

Anonymous (not verified)

tyeset

Anonymous (not verified)

I put this in a module, but not having and luck preventing the redirect:

<?php

/**
* Implementation of hook_comment_form_submit().
*/

function comment_no_redirect_comment_form_submit(&$form, &$form_state) {
$form_state['redirect'] = ltrim($form['#action'], '/');
}

/**
* Implementation of hook_comment_form_alter().
*/

function comment_no_redirect_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'comment_form') {
$form['#action'] = request_uri();
$form['#submit'][] = 'noredirect_comment_form_submit';
}
}

Anonymous (not verified)

er fixed, i'd renamed the module had omitted to rename the function call :

$form['#submit'][] = 'noredirect_comment_form_submit';

Anonymous (not verified)

Being banging my head against a wall and trying to use rules to prevent comment submission redirecting back to node. I'm using views panels to add the comment form onto the node edit page (i'm using comments with the node comment module ) as a way for admin to store detailed , time stamped notes on a node.

Any chance of rolling the above into a downloadable module??? :-)

Thanks again

© 2010-2014 Saigonist.