address_autocomplete

Definition

address_autocomplete($country, $string = '')
ecommerce-5--4/address/address.module, line 64

Description

Create a list of states from a given country

Parameters

$country String, the country code

$string String (optional), the state name typed by user

Return value

Javascript array, list of states

Code

<?php
function address_autocomplete($country, $string = '') {
  $string = strtolower($string);
  $string = '/^'. $string .'/';
  $matches = array();
  include_once drupal_get_path('module', 'store') .'/store.localization.inc';
  $states = _store_location_states($country);

  if (!empty($states)) {
    while (list($code, $name) = each($states)) {
      if ($counter < 5) {
        if (preg_match($string, strtolower($name))) {
          $matches[$code] = strtolower($name);
          ++$counter;
        }
      }
    }
  }
  echo drupal_to_js($matches);
  exit();
}
?>