Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 0 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
add comment

Your Answer

 
discard

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.