function chado_project_validate

2.x tripal_project.chado_node.inc chado_project_validate($node, $form, &$form_state)
3.x tripal_project.chado_node.inc chado_project_validate($node, $form, &$form_state)
1.x tripal_project.module chado_project_validate($node)

Implements hook_validate(). Validates submission of form when adding or updating a project node

Related topics

File

legacy/tripal_project/includes/tripal_project.chado_node.inc, line 197
Implement the project node content type

Code

function chado_project_validate($node, $form, &$form_state) {

  // We only want to validate when the node is saved.
  // Since this validate can be called on AJAX and Deletion of the node
  // we need to make this check to ensure queries are not executed
  // without the proper values.
  if (property_exists($node, "op") and $node->op != 'Save') {
    return;
  }

  // we are syncing if we do not have a node ID but we do have a project_id. We don't
  // need to validate during syncing so just skip it.
  if (!property_exists($node, 'nid') and property_exists($node, 'project_id') and $node->project_id != 0) {
    return;
  }

  // trim white space from text fields
  $node->title = property_exists($node, 'title') ? trim($node->title) : '';

  $project = 0;
  // check to make sure the name on the project is unique
  // before we try to insert into chado.
  if (property_exists($node, 'project_id')) {
    $sql = "SELECT * FROM {project} WHERE name = :name AND NOT project_id = :project_id";
    $project = chado_query($sql, array(':name' => $node->title, ':project_id' => $node->project_id))->fetchObject();
  }
  else {
    $sql = "SELECT * FROM {project} WHERE name = :name";
    $project = chado_query($sql, array(':name' => $node->title))->fetchObject();
  }
  if ($project) {
    form_set_error('title', t('The unique project name already exists. Please choose another'));
  }
}