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

I have yet to find a snippet or a solution to enforce a minimum comment length.

Most validation modules deal with fields.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Add a custom validator to form using hook_form_alter in your custom module.

function custom_mod_form_alter(&$form, &$form_state, $form_id){
  switch($form_id){
    case 'comment_form':
      $form['#validate'] = array_merge( $form['#validate'], array('custom_validator'));
    break;
  }
}

Define the logic to restrict the length of comment length

function custom_validator($form, $form_state){
    if(strlen($form_state['values']['comment']) < 50)
       form_set_error('comment', t('No No....'));
}
share|improve this answer

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.