function tripal_cv_cvterm_edit_form_validate

2.x tripal_cv.cvterm_form.inc tripal_cv_cvterm_edit_form_validate($form, &$form_state)
3.x tripal_chado.cv.inc tripal_cv_cvterm_edit_form_validate($form, &$form_state)

Validate cvterm edit form

Related topics

File

tripal_cv/includes/tripal_cv.cvterm_form.inc, line 261
Provides a form for creating & editing chado controlled vocabularies

Code

function tripal_cv_cvterm_edit_form_validate($form, &$form_state) {
  $cv_id = array_key_exists('cv_id', $form_state['values']) ? $form_state['values']['cv_id'] : '';
  $db_id = array_key_exists('db_id', $form_state['values']) ? $form_state['values']['db_id'] : '';
  $name = array_key_exists('name', $form_state['values']) ? $form_state['values']['name'] : '';
  $cvterm_id = array_key_exists('cvterm_id', $form_state['values']) ? $form_state['values']['cvterm_id'] : '';
  $accession = array_key_exists('accession', $form_state['values']) ? $form_state['values']['accession'] : '';

  $step = $form_state['storage']['step'];

  // make sure the cv term name is unique for this vocabulary
  if ($step == 1) {
    $values = array('name' => $name, 'cv_id' => $cv_id);
    $results = chado_select_record('cvterm', array('cvterm_id'), $values);
    foreach ($results as $r) {
      if ($r->cvterm_id != $cvterm_id) {
        form_set_error('name', 'The term name must be unique for this vocabulary. Another term with this name already exists.');
      }
    }
  }
}