ClassicPress / ClassicPress-v2

NOT READY FOR PRODUCTION.
GNU General Public License v2.0
13 stars 4 forks source link

💡 Enable Client-side Comment Form Validation #193

Closed DangitRick closed 1 year ago

DangitRick commented 1 year ago

Context

Many browsers supporting HTML5 are able to do client-side checks on form fields such as required, url, and email fields to ensure that the form content is filled out properly beforehand.

The ClassicPress comment form outputs valid HTML5 fields when themes declare support for HTML5; however, it also outputs a novalidate attribute into the form declaration. This prevents client-side validation, allowing incorrectly filled-out forms to be submitted. When this occurs, the user is greeted by a generic WordPress error and they must go back to the form, fix the problem, and resubmit.

Enabling client-side comment form validation has a few advantages:

Possible implemantion

Example of a default comment form error message, showing that a required field hasn't been filled out:

Screenshot 2023-08-29 at 11 43 51 AM

HTML5 validation on the same form, as seen in Safari 17:

Screenshot 2023-08-29 at 11 44 58 AM

An example of what an invalidly formatted email address would show:

Screenshot 2023-08-29 at 11 46 26 AM

Possible Solution

By replacing this:

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

with this:

            printf(
                '<form action="%s" method="post" id="%s" class="%s">',
                esc_url( $args['action'] ),
                esc_attr( $args['id_form'] ),
                esc_attr( $args['class_form'] )
            );

in wp-includes/comment-template.php, HTML5 client-side validation will work as expected.

Will you be able to help with the implementation?

I have a pull request ready to go.

xxsimoxx commented 1 year ago

Closed by #194.