You are here

function name_custom_formats_form_validate in Name Field 6

Same name and namespace in other branches
  1. 7 name.admin.inc \name_custom_formats_form_validate()

Custom validation for name_custom_formats_form().

File

./name.admin.inc, line 207
General administration functions.

Code

function name_custom_formats_form_validate($form, &$form_state) {
  $values = $form_state['values'];

  // Ensure that the name is unique
  if (empty($values['ncfid'])) {
    $count = db_result(db_query("SELECT count(*) FROM {name_custom_format} WHERE name = '%s'", $values['name']));
    $mcount = db_result(db_query("SELECT count(*) FROM {name_custom_format} WHERE machine_name = '%s'", $values['machine_name']));
  }
  else {
    $count = db_result(db_query("SELECT count(*) FROM {name_custom_format} WHERE name = '%s' AND ncfid <> %d", $values['name'], $values['ncfid']));
    $mcount = db_result(db_query("SELECT count(*) FROM {name_custom_format} WHERE machine_name = '%s' AND ncfid <> %d", $values['machine_name'], $values['ncfid']));
  }
  if ($count) {
    form_set_error('name', t('The name you have chosen is already in use.'));
  }
  if ($mcount) {
    form_set_error('machine_name', t('The machine readable name you have chosen is already in use.'));
  }
  elseif ($values['machine_name'] == 'default') {
    form_set_error('machine_name', t('The machine readable name you have chosen is reserved.'));
  }

  // Parse the string for un-matched backets.
  // TODO
  //  if ($format = $values['format']) {
  //    $format = _name_custom_formats_form_validate_format(str_replace('\\\\', "\t", $format));
  //    $format = str_replace(array('\\(', '\\)'), array('', ''), $format);
  //    if (strpos($format, '(') !== FALSE || strpos($format, ')')) {
  //      // Just a warning.
  //      drupal_set_message(t('There was one or more un-matched and un-escaped brackets in the format string %format.', array('%format' => $values['format'])), 'warning');
  //    }
  //  }
}