2

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

2

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');
-1

If you set format of the comment form to xhtml, the "novalidate" will be removed. Like this

$comments_args = array(             
                'format'            => 'xhtml'
            );
            comment_form($comments_args);
-1

Use this function rather than comment_form()

function validate_comment_form(){
    ob_start();
    comment_form();
    echo str_replace('novalidate','data-toggle="validator" ',ob_get_clean());
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.