diff --git a/htdocs/core/ajax/ziptown.php b/htdocs/core/ajax/ziptown.php index 92db98c250d..af47b7fc77d 100644 --- a/htdocs/core/ajax/ziptown.php +++ b/htdocs/core/ajax/ziptown.php @@ -143,6 +143,9 @@ if (GETPOST('zipcode') || GETPOST('town')) { } echo json_encode($return_arr); +} elseif (GETPOSTISSET('country_codeid')) { + $formcompany = new FormCompany($db); + print $formcompany->select_state(GETPOST('selected', 'int', 1), GETPOST('country_codeid', 'int', 1), GETPOST('htmlname', 'alpha', 1), GETPOST('morecss', 'alpha', 1)); } $db->close(); diff --git a/htdocs/core/class/html.formcompany.class.php b/htdocs/core/class/html.formcompany.class.php index 9ab8fa473dc..1d445094ea9 100644 --- a/htdocs/core/class/html.formcompany.class.php +++ b/htdocs/core/class/html.formcompany.class.php @@ -368,6 +368,32 @@ class FormCompany extends Form return $out; } + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Returns the drop-down list of departments/provinces/cantons for all countries or for a given country. + * In the case of an all-country list, the display breaks on the country. + * The key of the list is the code (there can be several entries for a given code but in this case, the country field differs). + * Thus the links with the departments are done on a department independently of its name. + * + * @param string $parent_field_id Parent select name to monitor + * @param integer $selected Code state preselected (mus be state id) + * @param integer $country_codeid Country code or id: 0=list for all countries, otherwise country code or country rowid to show + * @param string $htmlname Id of department. If '', we want only the string with