You are here

function search_api_location_page_search_form_submit in Search API Location 7.2

Form submission handler for the altered search_api_page_search_form().

See also

search_api_location_page_search_api_page_search_form_validate()

1 string reference to 'search_api_location_page_search_form_submit'
search_api_location_page_form_search_api_page_search_form_alter in search_api_location_page/search_api_location_page.module
Implements hook_form_FORM_ID_alter().

File

search_api_location_page/search_api_location_page.module, line 391

Code

function search_api_location_page_search_form_submit(array $form, array &$form_state) {
  if (is_array($form_state['redirect'])) {
    list($redirect, $url_options) = $form_state['redirect'];
  }
  else {
    $redirect = $form_state['redirect'];
    $url_options = array();
  }
  $url_options += array(
    'query' => array(),
  );
  $page = search_api_page_load($form_state['values']['id']);
  $num = 0;
  foreach ($page->options['search_api_location'] as $field) {
    if (!empty($field['enabled'])) {
      ++$num;
    }
  }
  if ($num == 1) {
    $params = _search_api_location_page_filter_parameters($form_state['values'], FALSE);
    $location = reset($params);
    $field = key($params);
    if ($field) {
      $field = substr($field, 0, -9);
      $url_options['query']['location'] = $location;
      if (!empty($form_state['values'][$field . '-radius'])) {
        $url_options['query']['radius'] = $form_state['values'][$field . '-radius'];
      }
    }
  }
  else {
    $url_options['query'] += _search_api_location_page_filter_parameters($form_state['values']);
  }
  if ($url_options) {
    $form_state['redirect'] = array(
      $redirect,
      $url_options,
    );
  }
}