function tripal_cv_cvterm_add_form_validate

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

Validate cv add form

File

tripal_chado/includes/tripal_chado.cv.inc, line 586

Code

function tripal_cv_cvterm_add_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'] : '';
  $accession = array_key_exists('accession', $form_state['values']) ? $form_state['values']['accession'] : '';

  $values = array('cv_id' => $cv_id);
  $results = chado_select_record('cv', array('name'), $values);
  if (!$results or count($results) == 0) {
    form_set_error('cv_id', 'The controlled vocabulary does not exist');
  }

  // make sure the DB exists
  $values = array('db_id' => $db_id);
  $results = chado_select_record('db', array('name'), $values);
  if (!$results or count($results) == 0) {
    form_set_error('db_id', 'The database name does not exist');
  }

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

  // make sure this accession is unique for the database
  $values = array('accession' => $accession, 'db_id' => $db_id);
  $results = chado_select_record('dbxref', array('dbxref_id'), $values);
  if (count($results) > 0) {
    form_set_error('accession', 'The accession is not uniuqe for this vocabulary\'s database.');
  }

}