You are here

function styles_ui_style_edit_form_validate in Styles 7.2

Validation handler for the edit style form.

File

contrib/styles_ui/styles_ui.admin.inc, line 255
Administrative page callbacks for the Styles UI module.

Code

function styles_ui_style_edit_form_validate($form, $form_state) {
  $field_type = $form_state['values']['field_type'];
  $style_name = $form_state['values']['name'];
  $old_style_name = $form_state['values']['old_style_name'];
  $styles = styles_default_styles();
  if (!preg_match('!^[a-z0-9_]+$!', $style_name)) {
    form_set_error('style_name', t('The machine-readable style name must contain only lowercase letters, numbers, and underscores.'));
  }
  else {
    if ($style_name != $old_style_name && !empty($styles[$field_type]['styles'][$style_name])) {
      form_set_error('style_name', t('The machine-readable style name %style_name is already taken.', array(
        '%style_name' => $style_name,
      )));
    }
  }
}