function tripal_stock_add_ONE_dbreference_form_validate

1.x tripal_stock-db_references.inc tripal_stock_add_ONE_dbreference_form_validate($form, &$form_state)

Implements hook_form_validate(): Validates the input from tripal_stock_add_ONE_dbreference_form()

Parameters

$form: An array describing the form that was rendered

$form_state: An array describing the current state of the form including user input

Related topics

File

tripal_stock/includes/tripal_stock-db_references.inc, line 107
@todo Add file header description

Code

function tripal_stock_add_ONE_dbreference_form_validate($form, &$form_state) {

  // Only ensure db reference valid if adding
  if ($form_state['clicked_button']['#value'] == t('Add Database Reference')) {
    //Do work of required validators
    if ($form_state['values']['accession'] == '') {
      form_set_error('accession', 'Accession field is Required.');
    }

    // Check database is valid db_id in chado
    if ($form_state['values']['database'] > 0) {
      $tmp_obj = db_fetch_object(chado_query("SELECT count(*) as count FROM {db} WHERE db_id=%d", $form_state['values']['database']));

      if ($tmp_obj->count != 1) {
        form_set_error('database', 'The database you selected is not valid. Please choose another one.');
      }
    }
    else {
      form_set_error('database', 'Please select a database');
    }

    // Check Accession is unique for database
    $tmp_obj = db_fetch_object(chado_query("SELECT count(*) as count FROM {dbxref} WHERE accession='%s'", $form_state['values']['accession']));

    if ($tmp_obj->count > 0) {
      form_set_error('accession', 'This accession has already been assigned to another stock.');
    }

  } //end of if adding

}