You are here

function cacheflush_preset_form_validate in CacheFlush 7

Same name and namespace in other branches
  1. 7.2 cacheflush.preset.inc \cacheflush_preset_form_validate()

Implements hook_formID_validate().

File

./cacheflush.preset.inc, line 124
Cacheflush module add/edit form for presets.

Code

function cacheflush_preset_form_validate(&$form, &$form_state) {

  // Create new preset.
  $form_state['cacheflush_preset_list'][$form_state['cacheflush_preset_id']]['#name'] = check_plain($form_state['values']['cacheflush_preset_name']);
  $form_state['cacheflush_preset_list'][$form_state['cacheflush_preset_id']]['#cacheflush_preset_values'] = array();
  $form_state['cacheflush_preset_list'][$form_state['cacheflush_preset_id']]['#enabled'] = TRUE;

  // Get all tabs checkboxes.
  $checkboxes = array();
  foreach ($form_state['cacheflush_vertical_tabs'] as $key => $value) {
    if (isset($form_state['values'][$key]) && $key != 'vertical_tabs_advance') {
      $checkboxes = array_merge($checkboxes, $form_state['values'][$key]);
    }
  }

  // Check the checkboxes value.
  foreach ($checkboxes as $key => $value) {
    if ($value == '1') {
      $pos = strpos($key, 'cacheflush_checkbox_');
      if ($pos !== FALSE) {
        list($null, $id) = explode('cacheflush_checkbox_', $key);
        $form_state['cacheflush_preset_list'][$form_state['cacheflush_preset_id']]['#cacheflush_preset_values'][$id] = $form_state['cacheflush_table_list'][$id];
      }
    }
  }

  // Check if any preset created.
  if (count($form_state['cacheflush_preset_list'][$form_state['cacheflush_preset_id']]['#cacheflush_preset_values']) < 1) {
    form_set_error(t('Presets'), t('You must select a table or create an advanced preset.'));
  }
}