You are here

function fieldgroup_edit_group_validate in Content Construction Kit (CCK) 6

Same name and namespace in other branches
  1. 5 fieldgroup.module \fieldgroup_edit_group_validate()

Group name validation for programmatic group addition.

@todo Come back here and do the same thing for groups as we've done for fields, present a machine-readable name field as well as a label instead of trying to create a machine-readable name from the label.

File

modules/fieldgroup/fieldgroup.module, line 178
Create field groups for CCK fields.

Code

function fieldgroup_edit_group_validate($form, &$form_state) {
  $form_values = $form_state['values'];
  $content_type = $form['#content_type'];
  $action = $form['#group_action'];
  if (!empty($form_values['group_name']) && $action == 'add') {
    $groups = fieldgroup_groups($content_type['type']);
    $group = $groups[$form_values['group_name']];
    if (isset($group[$form_values['group_name']])) {
      form_set_error('group_name', t('The group name %name already exists.', array(
        '%group_name' => $form_values['group_name'],
      )));
    }
    if (!preg_match('!^[a-z0-9_]+$!', $form_values['group_name'])) {
      form_set_error('group_name', t('The group name %name is invalid.', array(
        '%group_name' => $form_values['group_name'],
      )));
    }
  }
}