WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a comment form that has name, email, brief, detailed and rating fields.

The name, email, brief and rating need to be required, but the latter two are custom fields and I can only make them required through Javascript, but want to add proper WordPress/PHP validation to those fields.

The detailed field is actually the comment_field which is currently required, but I want to removed the required for this field, but I don't want to do it via the WordPress settings as I still want name and email to be required.

share|improve this question
up vote 1 down vote accepted

Here is a related question that should answer yours. Basicly you want to use the pre_comment_on_post hook

    function custom_validate_comment() {
    //validate for brief and rating
if( empty( $_POST['brief']) || empty( $_POST['rating'])  )
        wp_die( __('Error: you must fill in both the rating and the brief') );
//make comment not required
if(empy($_POST['comment']){$_POST['comment'] == "empty_comment";}

add_action('pre_comment_on_post', 'custom_validate_comment');

function custom_change_comment( $commentdata ) {
    if( $commentdata['comment'] == 'empty_comment' )
        $commentdata['comment'] = '';
    return $commentdata;

add_filter('preprocess_comment', 'custom_change_comment');

That should at least get you on the right track

share|improve this answer
Awesome, that worked perfectly. Thanks for the help! – WolfieZero Oct 18 '11 at 9:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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