cck_address_get_states uses state abbreviation as array key - states with same abbreviation will not show

matteusx - September 19, 2008 - 20:42
Project:Address field for CCK
Version:5.x-2.1
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

This portion of code from the cck_address_get_states shows how the state abbreviation is used as the key for the array of states returned:

  $results = db_query($sql);
  while ($result = db_fetch_object($results)) {
    $state_options[$result->state_abbrv] = $result->state_name;
  }
  return $state_options;

This is generally fine, unless you have multiple countries (and ask this function to show all states by not passing a country to it) and states in one country share the same abbreviation as states in another country. For example Australia has WA for Western Australia, and USA has WA for Washington. Regardless of which countries are currently supported or released, this problem will come up in the future.

I think this array should be indexed by the state_id field used in the cck_address_states database table. I am not sure of all the places this function is called from though or what the results of such a change would be. Just wanted to get this submitted.

#1

New Zeal - July 23, 2009 - 02:43
Status:active» fixed

Using country_select with the provided countries data avoids this issue by linking the state to the country.

#2

New Zeal - July 23, 2009 - 02:52
Status:fixed» closed
 
 

Drupal is a registered trademark of Dries Buytaert.