-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Omit novalidate
from comment form by default but introduce novalidate
arg to override
#8858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ibute to be omitted Fixes merge conflicts in applying https://core.trac.wordpress.org/attachment/ticket/47595/47595-novalidate_form-argument.0.diff
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Co-authored-by: Stephen A. Bernhardt <[email protected]>
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
src/wp-includes/comment-template.php
Outdated
@@ -2446,6 +2446,7 @@ function wp_list_comments( $args = array(), $comments = null ) { | |||
* @since 4.6.0 Introduced the 'action' argument. | |||
* @since 4.9.6 Introduced the 'cookies' default comment field. | |||
* @since 5.5.0 Introduced the 'class_container' argument. | |||
* @since n.e.x.t Introduced the 'novalidate_form' argument. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used this placeholder version since I wasn't sure how long it would take to merge this or if we'd target it for 6.8.2. But seems like it makes sense for a minor release, especially with the current relaxation of the criteria.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree; 6.8.2 seems reasonable. But with all the changes recently, I honestly don't have any idea...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 234cd63
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't really a request changes; it's more of an 'open to discussion'. I think that this is fine to go as is, but I feel there might be room for a clearer variable name. Feel free to dismiss if you disagree or feel it's a net neutral.
src/wp-includes/comment-template.php
Outdated
@@ -2446,6 +2446,7 @@ function wp_list_comments( $args = array(), $comments = null ) { | |||
* @since 4.6.0 Introduced the 'action' argument. | |||
* @since 4.9.6 Introduced the 'cookies' default comment field. | |||
* @since 5.5.0 Introduced the 'class_container' argument. | |||
* @since n.e.x.t Introduced the 'novalidate_form' argument. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree; 6.8.2 seems reasonable. But with all the changes recently, I honestly don't have any idea...
src/wp-includes/comment-template.php
Outdated
@@ -2646,6 +2648,7 @@ function comment_form( $args = array(), $post = null ) { | |||
), | |||
'comment_notes_after' => '', | |||
'action' => site_url( '/wp-comments-post.php' ), | |||
'novalidate_form' => false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if this would be clearer as novalidate_att
, and indicate that this is the behavior of the novalidate attribute. I'm on the fence about this, because we can't really avoid the double-negative. I'm not sure there's any foolproof way to communicate how the false state of a negative attribute is expressed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. I picked this name to parallel to keys like class_container
, id_form
, and name_submit
which is pattern is attribute name followed by the thing the attribute is for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense; it just doesn't follow the pattern used elsewhere in the same array. E.g. 'action' => "value of the action attribute".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By that argument, maybe it would just be 'novalidate' => false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consistency, apparently, is hard. ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It couldn't be relevant to any other element anyway, same as action
, as only the form
has either of these attributes. It's different for id
or class
when they can be on anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For another idea: use_novalidate
(which is similar to use_desc_for_title
in wp_list_categories()
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so because the other keys don't use a verb like that in this function. I like novalidate
as it can't be any simpler 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think just 'novalidate' makes sense. As @westonruter says, it's not valid on any other element, and it matches the method used for 'action'. Let's go with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, there we are! 3550454
novalidate
from comment form by default but introduce novalidate_form
arg to overridenovalidate
from comment form by default but introduce novalidate
arg to override
The comment form currently outputs a
FORM
tag with anovalidate
attribute if the theme supportshtml5
. This is obsolete now that browsers have greatly improved their support for client-side validation. Omitting this attribute helps ensure that a commenter does not accidentally submit an incomplete comment form, potentially risking losing the drafted comment (e.g. if the browser's bfcache is not enabled).With this PR, the
novalidate
attribute is omitted by default. If a site owner wants to retain thenovalidate
attribute on the comment form, they can opt-in via a filter, for example:Or when they can pass in this argument when the theme calls
comment_form()
:Trac ticket: https://core.trac.wordpress.org/ticket/47595
Commit Message
Comments: Remove
novalidate
attribute from comments form by default.Browser support for client-side validation is now reliable. Blocking the form submission when there is a missing/invalid field prevents the possibility of losing comment content when bfcache does not restore the page.
To retain the
novalidate
attribute, thecomment_form()
's args now accepts anovalidate
key which will add the attribute when it istrue
. This can also be supplied by thecomment_form_default_fields
filter, for example:{{{#!php
add_filter( 'comment_form_defaults', function ( $args ) {
$args['novalidate'] = true;
return $args;
} );
}}}
Fixes #47595.
Props westonruter, joedolson, sabernhardt.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.