You are here

function data_ui_create_form_validate in Data 7

Same name and namespace in other branches
  1. 6 data_ui/data_ui.admin.inc \data_ui_create_form_validate()

Validate handler for create table form.

File

data_ui/data_ui.admin.inc, line 352
Admin UI functions.

Code

function data_ui_create_form_validate($form, &$form_state) {

  // The table name is sanitized by the DataTable constructor.
  if (isset($form_state['storage']['name']) && data_get_table(trim($form_state['storage']['name']))) {
    form_set_error('name', t('Name is already taken.'));
  }
  if (isset($form_state['values']['field_num'])) {
    if (is_numeric($form_state['values']['field_num'])) {
      if ($form_state['values']['field_num'] < 1) {
        form_set_error('field_num', t('At least one field must be created.'));
      }
    }
    else {
      form_set_error('field_num', t('Enter a number greater than 0.'));
    }
  }

  // Check for duplicates.
  if (isset($form_state['values']['fields'])) {
    $names = array();
    foreach ($form_state['values']['fields'] as $field) {
      if (is_numeric($field['name'])) {
        form_set_error('name', t('Names can\'t be numbers.'));
      }
      elseif (!isset($names[$field['name']])) {
        $names[$field['name']] = $field['name'];
      }
      else {
        form_set_error('name', t('Names must be unique.'));
      }
    }
  }
}