You are here

function apachesolr_search_page_settings_form_validate in Apache Solr Search 6.3

Same name and namespace in other branches
  1. 8 apachesolr_search.admin.inc \apachesolr_search_page_settings_form_validate()
  2. 7 apachesolr_search.admin.inc \apachesolr_search_page_settings_form_validate()

Validation function for saving a search page

@todo Make sure we verify that the link is local

Parameters

type $form:

array $form_state:

File

./apachesolr_search.admin.inc, line 499
Administrative settings for searching.

Code

function apachesolr_search_page_settings_form_validate($form, &$form_state) {

  // Performs basic validation of the menu path.

  /*if (url_is_external($form_state['values']['search_path'])) {
      form_set_error('search_path', t('Path must be local.'));
    }*/
  $form_state['values']['search_path'] = trim($form_state['values']['search_path'], '/');
  if (empty($form_state['values']['search_path'])) {
    form_set_error('search_path', t('Path required.'));
  }
  if (!is_numeric($form_state['values']['advanced']['apachesolr_search_per_page'])) {
    form_set_error('advanced][apachesolr_search_per_page', t('The amount of search results must be an integer.'));
  }
  $form_state['values']['advanced']['apachesolr_search_per_page'] = (int) $form_state['values']['advanced']['apachesolr_search_per_page'];
  if (empty($form_state['values']['advanced']['apachesolr_search_per_page'])) {
    form_set_error('advanced][apachesolr_search_per_page', t('The amount of search results cannot be empty.'));
  }
  if ($form_state['values']['page_id'] == 'core_search') {
    if (!preg_match('@^search/[^/%]+$@', $form_state['values']['search_path'])) {
      form_set_error('search_path', t('The core Search page path must start with search/ and only have one /'));
    }
  }
  elseif (count(explode('%', $form_state['values']['search_path'])) > 2) {
    form_set_error('search_path', t('Only one % placeholder is allowed.'));
  }
  $page_id = strtolower(preg_replace(array(
    '/[^a-zA-Z0-9]+/',
    '/-+/',
    '/^-+/',
    '/-+$/',
  ), array(
    '_',
    '_',
    '',
    '',
  ), $form_state['values']['page_id']));
  if ($form_state['values']['page_id'] != $page_id && !empty($page_id)) {
    form_set_error('page_id', t('A unique machine-readable identifier for the search page configuration. It must only contain lowercase letters, numbers, and underscores.'));
  }
}