function tripal_stock_add_ONE_property_form_validate

1.x tripal_stock-properties.inc tripal_stock_add_ONE_property_form_validate($form, &$form_state)

Related topics

File

tripal_stock/includes/tripal_stock-properties.inc, line 86
@todo Add file header description

Code

function tripal_stock_add_ONE_property_form_validate($form, &$form_state) {

  // Only Require if Adding Property
  if ($form_state['clicked_button']['#value'] == t('Add Property')) {

    // Check that there is a stock
    if ($form_state['values']['prop_stock_id'] <= 0) {
      form_set_error('prop_stock_id', 'There is no associated stock.');
    }

    // Check that Selected a type
    if ($form_state['values']['prop_type_id'] == 0) {
      form_set_error('prop_type_id', 'Please select a type of property.');
    }
    else {
      // Check that type is in chado
      $num_rows = db_fetch_object(chado_query("SELECT count(*) as count FROM {cvterm} WHERE cvterm_id=%d", $form_state['values']['prop_type_id']));
      if ($num_rows->count != 1) {
        form_set_error('prop_type_id', "The type you selected is not valid. Please choose another one. (CODE:$num_rows)");
      } // end of if more or less than 1 row
    } // if no prop type

    // only check preferred synonym if type is synonym
    if ($form_state['values']['preferred_synonym'] == 1) {
      $tmp_obj = tripal_cv_get_cvterm_by_name('synonym', variable_get('chado_stock_prop_types_cv', 'null'));
      if ($form_state['values']['prop_type_id'] != $tmp_obj->cvterm_id) {
        form_set_error('preferred_synonym', 'Preferred Synonym Checkbox Only Applicable if Type of Property is Synonym');
      }
    }

  } // if add Property

}