I have a node then users may put comments on it. Ok fine. After reaching max limit of comments on one page (30 comments), the next comments would be on 2nd page and so on.

The problem is when users commenting on 2nd page (3rd, 4th, ...) users get redirected to first page of the comments! I want when users commenting on 2nd page, for example, users will be still on 2nd page (current page) and give users 'updated' page with their comments.

How to solve this?

Regards

Comments

pramudya81’s picture

anyone please...?

vm’s picture

The only thing I can think of would be to investigate the global redirect.module

beautifulmind’s picture

You have to append current location in the action property of the comment form using coding in hook_form_alter()
Thus, when your user adds comment from any page, they will be redirected to the same page, only if the form is displayed in line with the comment listing and not on the next page.

:)

Beautifulmind
Know more

Regards.
🪷 Beautifulmind

pramudya81’s picture

No idea on your suggestion, beautiful mind. Can you show how to achieve this? :)

beautifulmind’s picture

Say url in your browser's address bar reads: "http://www.mysite.com/node/25"
Now in one of your module files add following code.

function hook_form_alter($form_id, $form) {
  if($form_id == 'node_comment_form') {
     $ss__action = str_replace('//', '/', $_SERVER['REQUEST_URI']);
     $form['#action'] = $ss__action;
  }
}

This will redirect the page back to where it is.
And please let me know if this works for you, I have some other solutions too. ;)

:)

Beautifulmind
Know more

Regards.
🪷 Beautifulmind

pramudya81’s picture

No, it did not work out for me. May be I did this wrong? I added the codes above on my comment.module.
But no works. Any other solutions, beautifulmind?

Regards

beautifulmind’s picture

Do not alter any core module ever.
Just make another module and put this code in it.

unction hook_form_alter($form_id, $form) {
  if($form_id == 'node_comment_form') {
    $ss__destination = ($_REQUEST['destination']) ? $_REQUEST['destination'] : $_SERVER['REQUEST_URI'];
    $form['#action'] = $form['#action'] .'&destination='. $ss__destination;
  }
}

Beautifulmind

Regards.
🪷 Beautifulmind

pramudya81’s picture

Oops. Sorry didn't know that.
However I tried this and didn't work out too.

I created new module called "fix_comment_pagination" and new file called "fix_comment_pagination.module" in it containing the codes you gave above.

NB: Putting this new module on /sites/all/modules/ then I couldn't enable this module on admin->build->modules. So I just copy this module and try to run it again. Did not work out.

Additional info:
- my nodes url : http://localhost/content/node_title
- my first page of comment on a node url : http://localhost/content/node_title?from=20&comments_per_page=10
- 2nd page url would be : http://localhost/content/node_title?page=1&from=20&comments_per_page=10
- 3rd page url would be : http://localhost/content/node_title?page=2&from=20&comments_per_page=10
and so on...

Can you help me?

Regards

beautifulmind’s picture

Humm....
If you have created a module and if it doesn't work, that means there is something wrong.
Can I have full code of your module if its comply with your privacy policy? :)

:)
Beautifulmind

Regards.
🪷 Beautifulmind

pramudya81’s picture

Ok. I don't mind giving you my codes. But which ones? Which modules? The comment and node modules are core modules.
While my fix_comment_pagination is exactly the codes you gave me.

Regards

beautifulmind’s picture

One of the remedy to your module that doesn't working is that please make sure that you have replaced the module name with that of 'hook'.
B'coz I have developed an entire project which has many things altered this way and its in single module with single 'hook' in the module that is "hook_form_alter".
If it still doesn't work, please do not hesitate to knock here :). But this time please paste all your code from the module you created.

:)

Beautifulmind

Regards.
🪷 Beautifulmind

pramudya81’s picture

Sorry I am not familiar with these Drupal stuffs. But I'll try :)
This is what I have for fix_comment_pagination.module on /sites/all/modules/fix_comment_pagination

/*
function hook_form_alter($form_id, $form) {
  if($form_id == 'node_comment_form') {
     $ss__action = str_replace('//', '/', $_SERVER['REQUEST_URI']);
     $form['#action'] = $ss__action;
  }
}
*/

function hook_form_alter($form_id, $form) {
  if($form_id == 'node_comment_form') {
    $ss__destination = ($_REQUEST['destination']) ? $_REQUEST['destination'] : $_SERVER['REQUEST_URI'];
    $form['#action'] = $form['#action'] .'&destination='. $ss__destination;
  }
}

Both function does not work out.

beautifulmind’s picture

Your code reads like:
[code]
/*
function hook_form_alter($form_id, $form) {
if($form_id == 'node_comment_form') {
$ss__action = str_replace('//', '/', $_SERVER['REQUEST_URI']);
$form['#action'] = $ss__action;
}
}
*/

function hook_form_alter($form_id, $form) {
if($form_id == 'node_comment_form') {
$ss__destination = ($_REQUEST['destination']) ? $_REQUEST['destination'] : $_SERVER['REQUEST_URI'];
$form['#action'] = $form['#action'] .'&destination='. $ss__destination;
}
}
[/code]

Now, just replace "hook" with "fix_comment_pagination" and try following code:

function fix_comment_pagination_form_alter($form_id, $form) {
if($form_id == 'node_comment_form') {
$ss__destination = ($_REQUEST['destination']) ? $_REQUEST['destination'] : $_SERVER['REQUEST_URI'];
$form['#action'] = $form['#action'] .'&destination='. $ss__destination;
}
}

:)
Beautifulmind

Regards.
🪷 Beautifulmind

pramudya81’s picture

Thanks for your info. But it does not work neither :(

When I put a comment on 4th page, I get directed to 1st page again.
1st page here I mean 1st page of comment of a single node.
Doesn't really manners page of particular node though.

Or perhaps we misunderstood each other here?

Regards

pramudya81’s picture

Anyone manage to handle this? :)

Regards

maartenvg’s picture

Make a directory 'sites/all/modules/comment_pagination_fix', and put these two files in it:

comment_pagination_fix.info

name = Comment Pagination Fix
description = Fixes the pagination bug after replying to a multi-page comment thread
dependencies = comment

and

comment_pagination_fix.module

<?php 
function comment_pagination_fix_form_alter($form_id, &$form) {
  if ($form_id == 'comment_form') {
    $form['#submit'] = array('comments_pagination_fix_form_submit' => array());
  }
}

function comment_pagination_fix_form_submit($form_id, $form_values) {
  $form_values = _comment_form_submit($form_values);
  if ($cid = comment_save($form_values)) {
    $page = (int)(comment_num_all($form_values['nid']) / variable_get('comment_default_per_page', 50));
    if ($page > 0) {
      $page_str = 'page='.$page;
    }
    return array('node/'. $form_values['nid'], $page_str, "comment-$cid");
  }
}

pramudya81’s picture

I followed this exactly...But no works :(

maartenvg’s picture

That's awefully strange. Could you please try it on a clean install (D5, right?) just to be sure where the problem lies? And you did turn the module on, right ;-)

pramudya81’s picture

Yes very strange... I even could not make a comment after enabling this module. Yes I turn on the module.

I tried on Drupal 5.7 clean install and the problem persist.

Does it work out for you? What version you are using...

Regards

maartenvg’s picture

Oops, I saw I made a mistake when copying it. .

Do you see the 4th line of comment_pagination_fix.module:
$form['#submit'] = array('comments_pagination_fix_form_submit' => array());

That should be without an 's' in 'comments', so change it to:
$form['#submit'] = array('comment_pagination_fix_form_submit' => array());

pramudya81’s picture

Great!! It works perfectly well now.

This is what I was expecting for long.

Thanks maartenvg. Maybe you should raise this issue so Drupal 6 and above could have this comment behaviour.

Regards

maartenvg’s picture

This has already been solved in D6, as far as I can tell.

pramudya81’s picture

Dear maartenvg,

Perhaps another future request would be a table to track revisions on comments.
Just like node_revisions. Thus we could give extra information to users that this node/comment has been changed by who and when.

What do you think?

I see that you are managing birthday module. I tried that module before but I never put it on my prod site. Cause I prefer to display users age on users profile rather than just option showing users DOB or not.

Hopefully this could improve birthday module anyway...

Regards

maartenvg’s picture

Perhaps another future request would be a table to track revisions on comments.
Just like node_revisions. Thus we could give extra information to users that this node/comment has been changed by who and when.

What do you think?

I think you should check out http://drupal.org/project/comment_revisions, it does just that :)

I see that you are managing birthday module. I tried that module before but I never put it on my prod site. Cause I prefer to display users age on users profile rather than just option showing users DOB or not.

I'll take it into consideration. BTW you can use _birthdays_show_age($user) to implement it yourself.

pramudya81’s picture

Great you know much about Drupal...

1. Thanks for comment revision module
2. Thanks for show_age script. I'll try this.

Regards