You are here

function content_taxonomy_tree_validate in Content Taxonomy 6

Same name and namespace in other branches
  1. 6.2 content_taxonomy_tree.module \content_taxonomy_tree_validate()

Validation function for the content_taxonomy_tree element

assigns the selected terms to the element additionally checks if terms are selected for required fields (if this check isn't already done by

1 string reference to 'content_taxonomy_tree_validate'
content_taxonomy_tree_elements in ./content_taxonomy_tree.module
Implementation of hook_elements().


./content_taxonomy_tree.module, line 143


function content_taxonomy_tree_validate($element, &$form_state) {
  $field = $form_state['#field_info'][$element['#field_name']];
  $field_key = $element['#columns'][0];
  $values = content_taxonomy_tree_form2data($element, $form_state, $field);

  //check for required fields

  //if $element['#value'] is empty, it's validated by

  //otherwise we have to check this by our own
  if ($field['required'] && is_null($values[0]['value']) && !empty($element['#value'])) {
    form_error($element[$field_key], t('!name field is required.', array(
      '!name' => $element['#title'],
  if ($field['multiple'] >= 2 && count($element['#value']) > $field['multiple']) {
    form_error($element[$field_key], t('%name: this field cannot hold more than @count values.', array(
      '%name' => t($field['widget']['label']),
      '@count' => $field['multiple'],
  form_set_value($element, $values, $form_state);