如何向评论表单标签添加属性?

时间:2017-06-27 作者:Run

如何向表单标记添加属性?下面是我的代码,但它没有添加我需要的属性:

$args = array(
    \'title_reply\'=>\'\',
    \'comment_notes_before\' => \'\',
    \'logged_in_as\' => \'\',
    \'class_form\' => \'form-comment form-submit\',
    \'comment_field\' =>  \'<div class="medium-12 columns">
        <label>
            <textarea placeholder="Message" name="message" class="form-input" rows="10" required></textarea>
            <span class="form-error">Yo, you had better fill this out, it\\\'s required.</span>
        </label>
    </div>\',
    \'submit_button\' => \'<div class="medium-12 columns">
            <input type="submit" class="button button-send" value="Send">
        </div>
    \'
);
comment_form($args);
它生成form 标记如下:

<form action="http://xxx/wp-comments-post.php" method="post" id="commentform" class="form-comment form-submit">
但我需要补充data-abide novalidate:

<form action="http://xxx/wp-comments-post.php" class="form-comment form-submit" id="formComment" data-abide novalidate method="post">
有什么想法吗?

1 个回复
SO网友:Farhad Sakhaei

使用此功能,而不是comment_form()

function validate_comment_form(){
    ob_start();
    comment_form();
    echo str_replace(\'<form\',\'<form attribute="value" \',ob_get_clean());
}

结束