jeudi 13 août 2020

How can I make a Checkbox Required?

I am building a website with WordPress, and while I was building the comments section of my site I came across an issue. Before submitting comments, users must check a checkbox that says they agree to the Commenting Policy, but after testing I have realized that users can still submit their comments without checking the box. How can I make this box required? I tried using aria-required="true", and "required" but that doesn't seem to work. Here is the full code for my comments template file "comments.php":

<?php

$comment_send = 'Submit';
$comment_reply = 'Join the Conversation';
$comment_reply_to = 'Reply';

$comment_author = 'NAME';
$comment_body = 'COMMENT';
$comment_cookies_1 = '<h4  class="commentcookietext">I HAVE READ AND AGREE TO THE COMMENTING    POLICY </h4>';

$comment_cancel = 'Cancel';

//Array
$comments_args = array(
//Define Fields
'fields' => array(
    //Author field
    'author' => '<p class="comment-form-author"><br /><input class="commentauthor"  id="author" name="author" aria-required="true" placeholder="' . $comment_author .'"></input> </p>',
    //Cookies
    'cookies' => '<input class="commentcookies" type="checkbox" name="cookieagreement" aria-required="true" required>' . $comment_cookies_1 . '</input>'    ),

// Change the title of send button
'label_submit' => __( $comment_send ),
// Change the title of the reply section
'title_reply' => __( $comment_reply ),
// Change the title of the reply section
'title_reply_to' => __( $comment_reply_to ),
//Cancel Reply Text
'cancel_reply_link' => __( $comment_cancel ),
// Redefine your own textarea (the comment body).
'comment_field' => '<p class="comment-form-comment"><br /><textarea class="commentfield"  id="comment" name="comment" aria-required="true" placeholder="' . $comment_body .'"></textarea> </p>',
//Message Before Comment
'comment_notes_before' => __( $comment_before),
// Remove "Text or HTML to be displayed after the set of comment fields".
'comment_notes_after' => '',
//Submit Button ID
'id_submit' => __( 'comment-submit' ),
//Submit Button Class
'class_submit' => __('commentsubmit'),
//Cancel Relpy Class
'cancel_reply_class' => __('commentreplycancel')
);
comment_form( $comments_args );

wp_list_comments();
?>



Aucun commentaire:

Enregistrer un commentaire