You are here

function quicktabs_form_validate in Quick Tabs 6.3

Same name and namespace in other branches
  1. 5 quicktabs.module \quicktabs_form_validate()
  2. 6 quicktabs.module \quicktabs_form_validate()
  3. 6.2 includes/admin.inc \quicktabs_form_validate()
  4. 7.3 quicktabs.admin.inc \quicktabs_form_validate()
  5. 7.2 includes/admin.inc \quicktabs_form_validate()

Validation handler for quicktabs admin page.

File

includes/admin.inc, line 494

Code

function quicktabs_form_validate($form, &$form_state) {

  // We don't want it to validate when we're just adding or removing tabs.
  if ($form_state['clicked_button']['#id'] == 'edit-submit-form') {
    if (empty($form_state['values']['machine_name'])) {
      form_set_error('machine_name', t('The quicktabs ID is required.'));
    }
    else {
      if (!preg_match('!^[a-z0-9_]+$!', $form_state['values']['machine_name'])) {
        form_set_error('type', t('The quicktabs ID must contain only lowercase letters, numbers, and underscores.'));
      }
    }
    if (empty($form_state['values']['title'])) {
      form_set_error('title', t('Title is required for the quicktab block.'));
    }
    else {
      if (!isset($form_state['values']['tabs'])) {
        form_set_error('', t('At least one tab should be created.'));
      }
      foreach ($form_state['values']['tabs'] as $j => $tab) {
        if (empty($tab['title'])) {
          form_set_error('tabs][' . $j . '][title', t('Title is required for each tab.'));
        }
        elseif ($tab['type'] == 'qtabs' && $tab['qtabs']['machine_name'] == $form_state['values']['machine_name']) {
          form_set_error('tabs][' . $j . '][qtabs][machine_name', t('You cannot put a quicktab inside itself.'));
        }
        elseif ($tab['type'] == 'view') {

          // Remove spaces from view arguments.
          $form_state['values']['tabs'][$j]['view']['args'] = str_replace(' ', '', $form_state['values']['tabs'][$j]['view']['args']);
        }
        elseif ($tab['type'] == 'callback') {
          $menu_item = menu_get_item($tab['callback']['path']);
          if (!$menu_item || $menu_item['type'] != MENU_CALLBACK) {
            form_set_error('tabs][' . $j . '][callback][path', t('You must enter a valid menu callback for the path.'));
          }
        }
      }
    }
  }
}