You are here

function location_form2api in Location 5

Parameters

$location: An associative array that has been submitted by an HTML form generated by location_form().

Return value

An associative array in which the submitted values are modified to pass to the location API as the $location parameter (excepting location_form()).

This means changing the province field to remove the country code and dash. For example: California is served by the key 'us-CA' in the location form and this is what is passed when it is submitted through a form generated by location_form().

This is changed to 'CA' in the returned array.

5 calls to location_form2api()
location_extra_form_submit in ./location.module
location_extra_form_validate in ./location.module
location_handler_filter_eq in contrib/location_views/location_views.module
location_nodeapi in ./location.module
Implementation of hook_nodeapi().
location_user in ./location.module

File

./location.inc, line 368

Code

function location_form2api($location = array()) {

  // The user may have selected a state/province, but did not specify a country
  if (isset($location['province']) && strlen($location['province']) && $location['province'] != 'xx') {
    if (!isset($location['country']) || isset($location['country']) && !strlen($location['country'])) {
      $location['country'] = substr($location['province'], 0, 2);
    }
  }
  $translated = array();
  $location = is_array($location) ? $location : array();
  foreach ($location as $key => $value) {
    $value = trim($value);
    if ($key == 'province') {
      if (strlen($value) && $value != 'xx') {

        // chop off the 2-letter code and the '-' from the front of the value
        $value = substr($value, 3);
      }
    }
    $translated[$key] = $value;
  }
  return $translated;
}