When you are on a node page (for example node/10) and you submit a comment and get a validation error, you are taken to a different url (for example comment/reply/50).

A lot of things rely on the path, and because you are on a node page but the path is comment/reply/[nid] things break.
For example, you no longer have some classes that were based on the path, and themes relying on this class will break.

Comments

superstar3826’s picture

Drupal 7
i have recreated this error
first i installed standard version
Created a blank page node with comments enabled
Submitted comment with blank comment body
result sent me to "http://localhost:8082/comment/reply/2"
expected results should have been "http://localhost:8082/node/reply/2"

BrockBoland’s picture

Assigned: Unassigned » BrockBoland
BrockBoland’s picture

Assigned: BrockBoland » Unassigned
Category: bug » feature

I tried this out locally to confirm the behavior and did some thinking about the issue. It's no longer a concern in 8.x because of a JS check for required fields: one cannot submit the comment form without the required fields filled.

This is bigger than just the comment error, though: the permalinks for individual comments are things like comment/2#comment-2. If changing this path, we would also change any other comment/x path, and to do so at this point in the D7 product cycle would be abnormal. However, we could consider making that change for D8 (though I don't know how tightly-coupled node and comment will be in D8: there's no reason that comments need to be restricted to nodes only and not used on other entity types, I would think).

I think that a better solution might be to do some preprocessing to add a class (or classes) to the comment/reply page for themers who need something to hook onto there, to style it like the node page.

rooby’s picture

Thanks for the investigation.

I tried this out locally to confirm the behavior and did some thinking about the issue. It's no longer a concern in 8.x because of a JS check for required fields: one cannot submit the comment form without the required fields filled.

What if the user is one of the evil ones that has javascript disabled?

This is bigger than just the comment error, though: the permalinks for individual comments are things like comment/2#comment-2. If changing this path, we would also change any other comment/x path, and to do so at this point in the D7 product cycle would be abnormal. However, we could consider making that change for D8 (though I don't know how tightly-coupled node and comment will be in D8: there's no reason that comments need to be restricted to nodes only and not used on other entity types, I would think).

Agreed, comments definitely should not be restricted to nodes.

I think that a better solution might be to do some preprocessing to add a class (or classes) to the comment/reply page for themers who need something to hook onto there, to style it like the node page.

That sounds like an alright solution for pre D8.

ivan zugec’s picture

Version: 7.x-dev » 8.x-dev
Issue tags: +Needs backport to D7
StatusFileSize
new1.01 KB

I have created a test which'll check the URL when the comment form is submitted without any body text. The test will fail if you are not redirected back to node/NID. I'm also changing the issue version to 8.x-dev, because I was able to replicate the issue in both 7.x and 8.x.

gremy’s picture

Assigned: Unassigned » gremy
gremy’s picture

Issue tags: -Needs backport to D7

I am currently working on a patch for this feature. It's 67% done.
I need to mention that since this is a feature request it will not be backported to Drupal 7.

gremy’s picture

StatusFileSize
new14.48 KB

This is as far as I got with the patch for today.
I replaced the menu items for comment/... with node/$nid/comment/....
I tried to cover all comment/... urls and callbacks.

I also need to update the Comments tests, because with the comment urls changing, they will fail.

I did not test this patch in any way, so please consider this.
So, if you have time before I do, please review the patch as it is now.

gremy’s picture

Status: Active » Needs review
gremy’s picture

Assigned: gremy » Unassigned

Status: Needs review » Needs work

The last submitted patch, comments-change.patch, failed testing.

droplet’s picture

Status: Needs work » Needs review

#8: comments-change.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, comments-change.patch, failed testing.

rooby’s picture

Status: Needs work » Needs review

This also affects things like views that take a node id argument from the path.

I will try to make some time to look further this effort soon as I think it is very important to fix.

I'd say if you went looking you would find an enormous number of drupal sites that have many bugs on the comment/reply page.

I will also look into making a contrib module for D7 that tries to work around as many of the issues surrounding this as possible.

rooby’s picture

Status: Needs review » Needs work

Hey I didn't change that.

rooby’s picture

Actually my comment about views default nid argument is not valid.
It does handle that but my particular site had another related issue.

tamer.kamel’s picture

if you need to stop redirect to comment/reply/%node
you just need to comment line 1875 file comment.module
from
if (empty($comment->cid) && empty($comment->pid)) {
$form['#action'] = url('comment/reply/' . $comment->nid);
}

to
if (empty($comment->cid) && empty($comment->pid)) {
// $form['#action'] = url('comment/reply/' . $comment->nid);
}

doliveros’s picture

Why not just manually set the form's ['#action'] to an empty string?

I got this working adding this line on a custom comment-wrapper.tpl.php file, placed in my theme directory :
$content['comment_form']['#action'] = ''; print render($content['comment_form']);

I guess it's also achievable with form_alter.

gremy’s picture

Status: Needs work » Needs review
StatusFileSize
new40.69 KB

I updated the tests so that they match the new menu changes.
There are still some tests that are failing on my machine, so can someone please help me out with this.

Status: Needs review » Needs work

The last submitted patch, comments-change.patch, failed testing.

gremy’s picture

I changed the patch name to match the convention [project_name]-[description]-[issue_number]-[comment_id].patch.

gremy’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, drupal-comment-menu-changes-1609256-20.patch, failed testing.

gremy’s picture

Status: Needs work » Needs review
StatusFileSize
new38.43 KB

Fixed patch format

Status: Needs review » Needs work

The last submitted patch, drupal-comment-menu-changes-1609256-23.patch, failed testing.

gremy’s picture

My patch replaces all comment/... paths with node/[nid]/comment/....
Do you think this might be a correct solution?

gremy’s picture

Status: Needs work » Needs review

I just took another look at the issue queue, and saw this task: https://drupal.org/node/731724
I think it makes a lot of sense to decouple the Comment entity from the Node, and thus I believe that it makes the current issue irrelevant, and I believe this issue should be closed.

star-szr’s picture

Status: Needs review » Postponed

Let's mark this postponed for now then.

star-szr’s picture

Issue summary: View changes

Changing the comment reply url to be correct.

mgifford’s picture

SegementOfAnOrange’s picture

Re: #18

This did the trick for me:

mymodule_form_comment_form_alter(&$form, &$form_state) {
    $form['#action'] = "";
}
mukila’s picture

Re #30
If you use this one, you will need to redirect the page otherwise if you refresh the page you will get same error
i don't know it is the standard method but i use this one.. it works fine for me

function mymodule_form_comment_form_alter(&$form, &$form_state, &$form_id){
  array_unshift($form['#validate'],'custom_validate_comments');	
  unset($form['#action']);
}
function custom_validate_comments(&$form, &$form_state, $form_id) {
  if(empty($form_state['values']['comment_body']['und'][0]['value'])){
     drupal_goto($_GET['q']);
  }
}

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

milos.kroulik’s picture

Re #31 This works, but I had to change redirection target to make it work with clean URL. Also, filled in field values are deleted...

EDIT: Simply doing

$form['#action'] = '';

was enough to make it work for me.

mgifford’s picture

Status: Postponed » Active

#731724: Convert comment settings into a field to make them work with CMI and non-node entities is fixed, so no need to postpone this any more from what I can tell.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

acbramley’s picture

Status: Active » Needs review
StatusFileSize
new859 bytes

This bit us when using reCaptcha on comment forms. If the user doesn't validate captcha, they're redirected to the reply form. The reply form hides the comment form from the main page build so it results in a comment form at the bottom of the page, potentially in a different position which is bad UX. I'm interested to see what tests fail without the action being set in CommentForm as removing it does fix the issue however I assume it will affect threaded comments.

Status: Needs review » Needs work

The last submitted patch, 39: 1609256-39.patch, failed testing. View results

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

florianmuellerch’s picture

StatusFileSize
new849 bytes

Ported the patch to be usable in Drupal 8.8.2 (different line numbers).

hardik_patel_12’s picture

Status: Needs work » Needs review

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

manish.upadhyay’s picture

StatusFileSize
new875 bytes

Patch for 8.9 Drupal release.

Status: Needs review » Needs work

The last submitted patch, 46: 1609256-46.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.