You are here

function ds_fieldgroup_form_validate in Display Suite 6

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

Validate new custom fieldgroup submission.

File

includes/ds.groups.inc, line 154
Manage fieldgroups.

Code

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

    // Prepend with 'ds_group'.
    $form_state['values']['key'] = 'ds_group_' . $form_state['values']['key'];
  }
}