How do I make wordpress comment fields required?

Here is my form:

<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform" class="validate">  
   <?php if($user_ID) : ?>  
   <?php else : ?>
   <div class="label_container">
      <div class="left">
         <label for="author" class="label label_name">Name*</label>                 
      </div>
      <div class="right">
         <label for="email" class="label label_email">Email*</label>              
      </div>
      </div>
   <div class="input_container">
      <input id="name" name="author" class="required input_text input_name" type="text" value="" /> 
      <input id="email" name="email" class="required input_text email input_email" type="text" value="" />
   </div>         
   <?php endif; ?>
      <div class="label_container"> 
         <label for="comment" class="label label_comment">Comment</label>                 
      </div>
   <textarea id="comment_box" class="required input_comment" name="comment" cols="40" rows="6"></textarea>   
   <p><input name="submit" class="input_submit" type="submit" id="submit" tabindex="5" value="Submit Comment" />  
   <input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" /></p>  
   <input type="hidden" id="redirect_to" name="redirect_to" value="<?php echo get_bloginfo('wpurl');?>/comment">
   <?php do_action('comment_form', $post->ID); ?>  
</form>

I have required fields on all inputs, but it is only working on the comment text field.

Any ideas?

2 Answers
2

First of all, I highly recommend using the comment_form() function. It’s all of the above code in one line (more if you need to tweak parts of the code). You can designate name and email as required in the settings section of your admin area:

Discussion settings

Leave a Comment