You are here

function ds_code_field_form_validate in Display Suite 6

Same name and namespace in other branches
  1. 6.3 includes/ds.fields.inc \ds_code_field_form_validate()
  2. 6.2 includes/ds.fields.inc \ds_code_field_form_validate()

Validate code field submission, only on insert.

File

includes/ds.fields.inc, line 278
Manage fields.

Code

function ds_code_field_form_validate($form, &$form_state) {
  if ($form['#form_type'] == 'insert') {
    $module = $form['#module'];
    $fields = $form['#all_fields'];
    $existing = array_keys($fields);
    if (in_array($form_state['values']['code_key'], $existing)) {
      form_set_error('code_key', t('This field already exists.'));
    }
    if (!preg_match('!^[a-z_0-9]+$!', $form_state['values']['code_key'])) {
      form_set_error('code_key', t('The machine-readable name must contain only lowercase letters, numbers and underscores.'));
    }
  }
}