Opened 6 years ago
Last modified 15 months ago
#4332 accepted enhancement
Unusable comment error pages
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | Comments | Version: | 1.5 |
| Severity: | normal | Keywords: | needs-patch |
| Cc: | janbrasna, wp@…, shamess |
Description (last modified by foolswisdom)
No comment error page requires browser navigation to leave
ENV: WP trunk r5486
While viewing a post, I click Submit Comment without entering any information and the result is (wp-comments-post.php):
WordPress
Error: please type a comment.
Dead end: no link back to the page where I meant to comment or maybe accidentally clicked the button, and "Error:" makes me feel stupid ;-)
POSSIBLE SOLUTION
I don't see any reason to navigate away from the post post.
ADDITIONAL DETAILS
Assuming the error page is desirable (sure hope not), being able to style it might be useful.
Attachments (2)
Change History (25)
comment:1
foolswisdom — 6 years ago
- Description modified (diff)
- Milestone changed from 2.4 to 2.3
- Owner changed from anonymous to rob1n
- Status changed from new to assigned
- Version 2.3 deleted
comment:4
markjaquith — 6 years ago
I like the JS idea. Disable the submit button and re-enable it when all required fields are filled.
comment:6
markjaquith — 6 years ago
- Milestone changed from 2.3 to 2.4 (next)
- Owner changed from rob1n to markjaquith
- Status changed from new to assigned
Seems like a good idea for 2.4
- Cc janbrasna added
- Keywords comment error page usability dev-feedback 2nd-opinion added
- Milestone changed from 2.9 to 2.8
- Priority changed from low to normal
- Severity changed from minor to normal
- Summary changed from No comment error page requires browser navigation to leave to Unusable comment error pages
- Version set to 1.5
- Cc wp@… added
How about something like this? For those with javascript disabled maybe add in a back link to that error page?
- Keywords has-patch added
I decided to try fixing this myself, just to see if I could. Turns out I sort of have it; on comment submit, instead of using wp_die() to give the error messages, I just redirected back to the post, passing it an error code. That error code is rendered by the action "comment_form_errors" which template designers will have to implement themselves. "comment_form_errors" echos the error text.
This doesn't use javascript at all, so there's no problem with worrying about them having it disabled. I figured Javascript should supplement a server side error response, not entirely replace it anyway.
There are a few things that I don't like about this way though:
- It relies on the template designer to add the action before the poster can see their errors. A lot of themes being used are orphaned now, and likely won't ever get updated again. Changing the WordPress source to use this method would abandon all those who don't update their themes, or whose themes aren't updated.
- It uses a GET variable, which generally makes the URL look ugly. I wouldn't say that's a majour problem though.
- Sending the data as a POST would require the use of curl, a library that isn't switched on in PHP by default and so isn't suitable to use in WordPress
- I tried holding this data in a session, but that didn't work for some reason...
- It echos, rather than returns. That makes it harder for theme developers to work with the data it returns.
- On the redirect back, all the comment fields are blank again. This could be hugely annoying if the user just spent an hour writing an awe inspiring comment, only to accidentally have left out their email address, and lose the comment. This is a problem mostly causes by me not knowing how to best transfer data from wp-comments-post.php back to the post.
PS. This is my first time submitting anything to an open source project, so this is more a learning experience for me rather than me aiming to add an awesome contribution. If I've done something wrong in the way of submitting this, or I've done bad open source coding conventions, email me please at (it may be a bit off topic in here): shamess at gmail dot com.
- Keywords needs-patch added; comment error page usability dev-feedback 2nd-opinion has-patch removed
+1 to the idea in the patch, but the patch itself needs some work:
- add_query_arg() and wp_redirect() should be used
- a new hook should not be introduced, to ensure backward compat with themes that don't have it. maybe use the comment_form hook instead, with a very low (0) priority.
- one of the error messages is not localizable
comment:11
shamess — 4 years ago
- Cc shamess added
- Keywords has-patch needs-testing added; needs-patch removed
Fixed according to Denis-de-Bernardy's notes. I had no idea those two functions existed.
I added the hook to comment_form, but the change might be a little surprising to users, which is why I didn't implement it on the first patch I gave. I gave it a lower priority (which is a higher is lower...) so hopefully it won't break other things.
Changed the text of the error message that was mentioned and made it localisable.
- Keywords tested 2nd-opinion added; needs-testing removed
function and variable names might also need to be made consistent with the rest of WP, but else works.
err... actually not, there are die calls missing after wp_redirect().
nevermind, I'm blind. :D
comment:15
ryan — 4 years ago
The redirect needs to be aware of comment paging. It should also use the reply anchor. Although in the case of inline replies, we won't be able to send the user back exactly to where there were. Showing an error page with a button that does history.back would be far less annoying because it would take me back to where I was.
- Keywords needs-patch added; has-patch tested 2nd-opinion removed
comment:17
ryan — 4 years ago
- Component changed from General to Comments
- Milestone changed from 2.8 to Future Release
see #9818
- Type changed from defect (bug) to enhancement
comment:22
SergeyBiryukov — 2 years ago
Related: #14984
comment:23
jane — 15 months ago
This is basically just begging for a javascript notice of required fields. Going to a separate page for an error message is so 5 years ago. Oh, wait. :)

We have the comment form hook. We could pass on an error number that is handled by the comment form hook and translated into a user-friendly message. We could also put in some JS that does client-side validation.