function chado_contact_validate

2.x tripal_contact.chado_node.inc chado_contact_validate($node, $form, &$form_state)
3.x tripal_contact.chado_node.inc chado_contact_validate($node, $form, &$form_state)
1.x tripal_contact.form.inc chado_contact_validate($node, &$form)

validates submission of form when adding or updating a contact node

Related topics

File

tripal_contact/includes/tripal_contact.form.inc, line 156

Code

function chado_contact_validate($node, &$form) {
  $title = trim($node->title);
  $contact_id = trim($node->contact_id);
  $unittype_id = trim($node->unittype_id);
  $description = trim($node->description);
  $num_properties = $node->num_properties;
  $num_new = $node->num_new;

  $contact = 0;
  // check to make sure the name on the contact is unique
  // before we try to insert into chado. If this is an update then we will
  // have a contact_id, therefore we want to look for another contact with this
  // name but with a different contact_id. If this is an insert, just look
  // for a case where the name already exists.
  if ($node->contact_id) {
    $sql = "
      SELECT * FROM {contact} 
      WHERE name = '%s' AND NOT contact_id = %d
    ";
    $contact = db_fetch_object(chado_query($sql, $title, $contact_id));
  }
  else {
    $sql = "SELECT * FROM {contact} WHERE name = '%s'";
    $contact = db_fetch_object(chado_query($sql, $title));
  }
  if ($contact) {
    form_set_error('title', t('The contact name already exists. Please choose another'));
  }

}