You are here

function availability_calendar_admin_settings_validate in Availability Calendars 7.5

Same name and namespace in other branches
  1. 7.3 availability_calendar.admin.inc \availability_calendar_admin_settings_validate()
  2. 7.4 availability_calendar.admin.inc \availability_calendar_admin_settings_validate()

Form validate callback for the admin_settings form.

  • At least one label should be filled.
  • Entered classes should be a valid css class.

_state

Parameters

array $form:

1 string reference to 'availability_calendar_admin_settings_validate'
availability_calendar_admin_settings in ./availability_calendar.admin.inc
Defines form callback for the admin/config/availability-calendar/settings page.

File

./availability_calendar.admin.inc, line 194

Code

function availability_calendar_admin_settings_validate($form, &$form_state) {
  $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
  if ($op == t('Save configuration')) {
    $element = $form_state['values']['states'];
    $all_empty = TRUE;
    foreach ($element as $i => $state_fields) {
      if (!empty($state_fields['label'])) {
        $all_empty = FALSE;
      }
      if (!empty($state_fields['css_class']) && $state_fields['css_class'] !== drupal_clean_css_identifier($state_fields['css_class'])) {
        form_set_error("states][{$i}][css_class", t('CSS class should be usable as a valid css class.'));
      }
    }
    if ($all_empty) {
      form_set_error('states][0][label', t('At least 1 state should be defined.'));
    }
  }
}