You are here

function apachesolr_search_page_settings_form_validate in Apache Solr Search 8

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

File

./apachesolr_search.admin.inc, line 454
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.'));
  }
}