How to Remove novalidate attribute from comment form

I’m using html5 support for input formats and custom comment form fields with this code:

<?php
        $commenter = wp_get_current_commenter();

        $args = wp_parse_args( $args );
        if ( ! isset( $args['format'] ) )
            $args['format'] = current_theme_supports( 'html5', 'comment-form' ) ? 'html5' : 'xhtml';

        $req = get_option( 'require_name_email' );
        $aria_req = ( $req ? " aria-required='true'" : '' );
        $html_req = ( $req ? " required='required'" : '' );
        $html5    = 'html5' === $args['format'];

        comment_form(
        array(
            'comment_notes_after' => '',
            'comment_field' => '<div class="comment-form-comment form-group"><label class="control-label" for="comment">' . __( 'Comment', 'odin' ) . '</label><div class="controls"><textarea id="comment" name="comment" cols="45" rows="8" class="form-control" aria-required="true" ></textarea></div></div>',
            'fields' => apply_filters( 'comment_form_default_fields', array(
                'author' => '<div class="comment-form-author form-group">' . '<label class="control-label" for="author">' . __( 'Name', 'odin' ) . ( $req ? '<span class="required"> *</span>' : '' ) . '</label><input class="form-control" id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . $html_req  . ' /></div>',
                'email' => '<div class="comment-form-email form-group"><label class="control-label" for="email">' . __( 'E-mail', 'odin' ) . ( $req ? '<span class="required"> *</span>' : '' ) . '</label><input class="form-control" id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . $html_req  . ' /></div>',
                'url' => '<div class="comment-form-url form-group"><label class="control-label" for="url">' . __( 'Website', 'odin' ) . '</label>' . '<input class="form-control" id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></div>' ) )
        )
    ); ?>

Leaving everything ready for validation html5, except for the novalidade attribute of the tag.
I am currently removing with jQuery, but I wonder if there is some way via WP / PHP

3 Answers
3

It seems WP core adds the novlidate attribute to the comment form when your theme has HTML5 support enabled for comment forms (see includes/comment-template.php).

To disable it, use

remove_theme_support('html5', 'comment-form');

Leave a Comment