Make WordPress Core

Opened 11 years ago

Closed 9 years ago

#24799 closed defect (bug) (duplicate)

Default comment form title and div id attributes prevent multiple use of comment form on a page

Reported by: bjornw's profile BjornW Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Comments Keywords:
Focuses: Cc:


The current trunk implementation of the comment form will cause issues with multiple comment forms on a page due to using non-unique id attributes in the html. Most of this can be fixed using filters or parameters fed to the comment_form() function, except for the id attribute of the h3 title and the parent div. The non-unique ids of these twho html tags prevent us from reusing the comment form multiple times on a page without issues.

The easiest, backwards compatible, solution seems to me is adding two optional variables to the array of parameters supplied to comment_form().

A better solution in my opinion, but which would take more time & testing, is to make sure all id attributes in the default comment form are unique by default. This can be done using the post-id (of the post on which the comment replies) in the id attribute to prepend or append the id with the unique post-id.

Attachments (2)

comment-template.diff (8.7 KB) - added by BjornW 11 years ago.
Make sure html id attributes are unique
trac#24799-fix-ids-in-comment-template.patch (8.1 KB) - added by BjornW 11 years ago.

Download all attachments as: .zip

Change History (8)

#1 follow-up: @nacin
11 years ago

I think an argument that removes all IDs is probably the best idea. Maybe in the process it adds a single comment-form-$post_id ID.

#2 in reply to: ↑ 1 @BjornW
11 years ago

Replying to nacin:

I think an argument that removes all IDs is probably the best idea. Maybe in the process it adds a single comment-form-$post_id ID.

Ok, so it's not a feature that a comment form may be used only once on a page. Just checking before I'd start on a patch for this :)

#3 @BjornW
11 years ago

  • Keywords has-patch added

Heres's a patch to make sure WordPress uses unique html id attributes by default in the comment form. What I have done is appended the post_id to the comment form html where needed and I have added extra options to the comment_form() options so one can change the html before and after a form as well as change the h3 title into something else.

It's a quick hack briefly tested and it seems the duplicate ids are now gone, but it could use some more testing and maybe some feedback if this is the right way to deal with this issue.

ps: It's been a while since I submitted a patch so I might be doing lots of things wrong. Just let me know and I'll try to alter my patch accordingly.

11 years ago

Make sure html id attributes are unique

#4 @nacin
11 years ago

  • Version changed from trunk to 3.0

#5 @BjornW
11 years ago

I've changed content.php of the TwentyThirteen theme to use as a test: instead of displaying a comment link using comments_popup_link(), I'm using comment_form() to directly display the comment form beneath each post and this will cause multiple html validation errors due to id's being used multiple times on a page. After applying my patch all id errors are gone and you will be able to use multiple comment forms in your theme. This needs more testing especially by theme builders. My new patch is applicable for rev25588 of comment-template.php

11 years ago


#6 @rachelbaker
9 years ago

  • Keywords dev-feedback has-patch removed
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #30909, which has more recent activity.

Note: See TracTickets for help on using tickets.