You are here

function _ip_geoloc_process_go_to_submit in IP Geolocation Views & Maps 7

Submit handler to either go to a Region or "Move to" a street address.

Stores the geocoded lat/long and address info on the session.

Parameters

array $form: A form array

array $form_state: The form's current state

1 string reference to '_ip_geoloc_process_go_to_submit'
ip_geoloc_set_location_form in ./ip_geoloc_blocks.inc
Form for finding the visitor or going to a region or street address.

File

./ip_geoloc_blocks.inc, line 746
Blocks available in IP Geolocation Views & Maps.

Code

function _ip_geoloc_process_go_to_submit($form, &$form_state) {

  // Clear any pending location retrieval process that may be in process.
  _ip_geoloc_set_session_value('last_position_check', time());
  _ip_geoloc_set_session_value('position_pending_since', NULL);
  $geo_vocabulary_id = variable_get('ip_geoloc_geo_vocabulary_id', 0);
  if (empty($form_state['values']['fixed_address'])) {

    // Nothing slected. As 'Go' was pressed we need to choose 1 or 2.
    $form_state['values']['fixed_address'] = $geo_vocabulary_id ? '2' : '1';
  }
  if ($form_state['values']['fixed_address'] == '1') {

    // Using new 'input' rather than current 'values'.
    $entered_address = isset($form_state['input']['street_address']) ? check_plain($form_state['input']['street_address']) : NULL;
    $location = ip_geoloc_set_location_from_address($entered_address);
  }
  elseif ($geo_vocabulary_id) {

    // "Region" selected.
    $location = ip_geoloc_set_location_from_region($form_state['values']['region']);
  }

  // Wipe old location before setting the new one (to avoid merging).
  _ip_geoloc_set_session_value('location', NULL);
  _ip_geoloc_set_session_value('location', $location);
  $redirect = variable_get('ip_geoloc_address_redirect');
  if (!empty($redirect)) {
    $form_state['redirect'] = $redirect;
  }

  // No need to remember the form state. It's all kept on the session.
  // Also, if set to TRUE, content is rendered before new location is set
  // and Region selector will be one step behind.
  $form_state['rebuild'] = FALSE;
}