function apachesolr_search_page_settings_form_validate in Apache Solr Search 7
Same name and namespace in other branches
- 8 apachesolr_search.admin.inc \apachesolr_search_page_settings_form_validate()
- 6.3 apachesolr_search.admin.inc \apachesolr_search_page_settings_form_validate()
File
- ./
apachesolr_search.admin.inc, line 457 - 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.'));
}
// Make sure we cannot get duplicate search page paths
foreach (apachesolr_search_load_all_search_pages() as $search_page) {
if ($form_state['values']['search_path'] == $search_page['search_path'] && $form_state['values']['page_id'] != $search_page['page_id']) {
form_set_error('search_path', t('The search path must be unique. This path is already in use by another search page.'));
}
}
}