Make WordPress Core

Opened 6 years ago

Closed 4 years ago

#42661 closed enhancement (duplicate)

html5 comments form validation doesn't work

Reported by: wordpreso's profile Wordpreso Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.6
Component: Comments Keywords:
Focuses: Cc:

Description

The default html5 validation doesn't work in the forms build by /wp-includes/comment-template.php

in the function comment_form( $args = array(), $post_id = null )

in the line 2298 of comment-template.php the sentence to create novalidate atribute has the values reversed and because of this it isn't going to validate in html5 forms :

<?php
<form action="<?php echo esc_url( $args['action'] ); ?>" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>" class="<?php echo esc_attr( $args['class_form'] ); ?>"<?php echo $html5 ? ' novalidate' : ''; ?>>

This sentence shouldn't be? :

<?php
<form action="<?php echo esc_url( $args['action'] ); ?>" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>" class="<?php echo esc_attr( $args['class_form'] ); ?>"<?php echo $html5 ? '' : 'novalidate'; ?>>

¿Or are you delegating this kind of validations to any other source code? in such case what sense have print or not this attribute here?

I attach the file with the correction from a previous versión but the bug, if it is a bug is in 4.9 source code too.

Thanks for reading and thanks for wordpress ;-)
Best regards

Attachments (1)

comment-template.php (85.2 KB) - added by Wordpreso 6 years ago.
wp-includes/comment-template.php from 4.7.5 WP version with this issue solved

Download all attachments as: .zip

Change History (5)

@Wordpreso
6 years ago

wp-includes/comment-template.php from 4.7.5 WP version with this issue solved

#1 @afercia
6 years ago

  • Type changed from defect (bug) to enhancement
  • Version changed from 4.9 to 3.6

@Wordpreso welcome to Trac and thanks for your report.

This is intentional, not a bug; see the related changeset https://core.trac.wordpress.org/changeset/23689

Following the argumentations in the related ticket #15080 the main concern was about browsers validation inconsistencies and errors. That was 7 years ago though. It is certainly possible to re-visit that decision and allow HTML5 validation but I'm not so sure about the browsers state on this regard. Is browsers validation fully and correctly working for all input fields in all languages, all date formats, all currency formats, all phone number formats, etc.? Is providing a pattern working in all browsers?

#2 @Wordpreso
6 years ago

¿Then who would decide or who would need this html5 web browser validations must add a filter in functions.php to modify this behavior?
¿There isn't any other mechanism to enable this html5 "standard" feature?

Thanks a lot for your fast and clear answer.

#3 @drozdz
4 years ago

It would make sense to at least add a filter that will allow to change this behavior...

It's a little bit weird decision and it makes no sens to force users to use output buffering just to remove this "novalidate" tag. Just take a look at this question and suggested solutions:

https://wordpress.stackexchange.com/questions/193776/how-to-remove-novalidate-attribute-from-comment-form

Last edited 4 years ago by drozdz (previous) (diff)

#4 @SergeyBiryukov
4 years ago

  • Component changed from General to Comments
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hi there, thanks for the ticket!

As noted above, the novalidate attribute on the form is intentional at the moment, it prevents client-side validation from being performed due to concerns about browsers implementing validation in very different ways, per discussion in #15080.

We're now re-evaluating that decision in #47595, let's continue the discussion there.

Note: See TracTickets for help on using tickets.