Custom Validation while adding a term under taxonomy I want to use custom validation while adding a term. I used form alter and #validate function it's not working.Default validation function under taxonomy module is working but my custom validate function is not.

Here is my code

  function lms2_validate_form_alter($form , &amp;$form_state, $form_id){

    if ($form_id == 'taxonomy_form_term'){          
      $form['#validate'][] = 'lms2_validate_term_validate';
    }
  } 

  function lms2_validate_term_validate($form ,&amp;$form_state){
      drupal_set_message('hello');
  }
In Drupal 7, if you go through hook_form_alter. 

It uses $form as a reference. You need to use &amp; before $form.


/**
 * Implements hook_form_alter
 */
function hook_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case 'taxonomy_form_term': 
      $form['#validate'][] = 'mymodule_taxonomy_form_custom_validate';
      break;
  }
}
/**
 * Implements hook_form_validate
 */
function hook_taxonomy_form_custom_validate($form, &$form_state) {
  //validation goes here
}


Let say if your module name is lms2_validate then use:


function lms2_validate_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'taxonomy_form_term') {
    $form['#validate'][] = 'lms2_validate_term_validate';
  }
}

function lms2_validate_term_validate($form, &$form_state) {
  drupal_set_message('hello');
}