Index: addresses.settings.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/addresses/addresses.settings.inc,v
retrieving revision 1.25
diff -u -r1.25 addresses.settings.inc
--- addresses.settings.inc	22 Jan 2009 02:52:52 -0000	1.25
+++ addresses.settings.inc	7 Feb 2009 20:35:29 -0000
@@ -68,7 +68,7 @@
   if (!empty($fields['province'])) {
     $form['province'] = array(
       '#default_value'  => isset($values['province']) ? $values['province'] : '',
-      '#maxlength'      => 16,
+      '#maxlength'      => 64,
       '#required'       => ($fields['province'] == ADDRESSES_FIELD_REQUIRED),
       '#size'           => 16,
       '#title'          => t('State / Province'),
@@ -193,15 +193,31 @@
   // Check if its a valid province.
   // It should be the Province code listed on the
   // given COUNTRY.inc file
-  if ($province = $form['province']['#value']
-      and $country = $form['country']['#value']
-      and $provinces = _addresses_province_get($country)
-      and empty($provinces[drupal_strtoupper($province)])) {
-
-    // Get the province fieldname
-    $field_name = $form['province']['#name'];
-    $field_name = drupal_substr($field_name, 0, -1);
-    $field_name = preg_replace('/([^]])\[/', '\1][', $field_name);
+
+  // Get the province fieldname
+  $field_name = $form['province']['#name'];
+  $field_name = drupal_substr($field_name, 0, -1);
+  $field_name = preg_replace('/([^]])\[/', '\1][', $field_name);
+
+  $province = $form['province']['#value'];
+  $country = $form['country']['#value'];
+  $provinces = _addresses_province_get($country);
+
+  // Check to see if the user put in the full name of the province. If they
+  // did, convert it to the province code. We can use the variable in t() here
+  // as it should be provided to translators elsewhere.
+  if ($province_code = _addresses_array_isearch(t($province), $provinces)) {
+    $province = $province_code;
+    // Break the field name into components.
+    preg_match_all('/(.+)]\[(.+)]\[(.+)/', $field_name, $matches, PREG_SET_ORDER);
+    $field_components = array($matches[0][1], $matches[0][2], $matches[0][3]);
+    $form_state['values'][$field_components[0]][$field_components[1]][$field_components[2]] = $province;
+  }
+
+  if ($province
+      && $country
+      && $provinces
+      && empty($provinces[drupal_strtoupper($province)])) {
 
     $countries = _addresses_country_get();
     form_set_error($field_name, t('Could not find %province as a province from %country. Try to use the province abbreviation or number.',
@@ -437,4 +453,23 @@
     );
   }
   return theme('table', array(), $rows, array('id' => 'addresses-field-weight')) . drupal_render($form);
-}
\ No newline at end of file
+}
+
+/**
+ * Case-insentitive array search. Used for the provinces field.
+ *
+ * @param $str
+ *   The string to search for.
+ * @param $array
+ *   The array to search in.
+ * @return unknown_type
+ */
+function _addresses_array_isearch($str, $array){
+    $str = strtolower($str);
+    foreach ($array as $k => $v) {
+      if (strtolower($v) == $str) {
+        return $k;
+      }
+    } 
+    return false;
+}
Index: addresses.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/addresses/addresses.module,v
retrieving revision 1.61
diff -u -r1.61 addresses.module
--- addresses.module	20 Jan 2009 20:31:42 -0000	1.61
+++ addresses.module	7 Feb 2009 20:35:29 -0000
@@ -70,7 +70,7 @@
       ),
       'province' => array(
         'type'        => 'varchar',
-        'length'      => 16,
+        'length'      => 64,
         'description' => t('Name of the state/province/county/territory'),
         'display'     => ADDRESSES_FIELD_SHOW,
         'title'       => t('Province'),
