function aggregator_form_category_validate

Form validation handler for aggregator_form_category().

See also

aggregator_form_category_submit()

File

drupal/modules/aggregator/aggregator.admin.inc, line 575
Administration page callbacks for the Aggregator module.

Code

function aggregator_form_category_validate($form, &$form_state) {
  if ($form_state['values']['op'] == t('Save')) {

    // Check for duplicate titles
    if (isset($form_state['values']['cid'])) {
      $category = db_query("SELECT cid FROM {aggregator_category} WHERE title = :title AND cid <> :cid", array(
        ':title' => $form_state['values']['title'],
        ':cid' => $form_state['values']['cid'],
      ))
        ->fetchObject();
    }
    else {
      $category = db_query("SELECT cid FROM {aggregator_category} WHERE title = :title", array(
        ':title' => $form_state['values']['title'],
      ))
        ->fetchObject();
    }
    if ($category) {
      form_set_error('title', t('A category named %category already exists. Enter a unique title.', array(
        '%category' => $form_state['values']['title'],
      )));
    }
  }
}