I've added the address format for Switzerland.
Further I've added some an autocompletion function to fetch the city and administrative area by a postal code.
To do so changes in the already existing address handlers were made.

Comments

sportel’s picture

Hi das-peter,

Nice mod. to the module. I can use it as an example for dutch addresses+autocompletion. But would it be possible to use data from a databasetable (with the cities and administrative areas)? I'm sort of a php-noob, so I wouldn't know how to do it, so if someone is willing to give an example, would be nice.

Thanks,
Mike.

das-peter’s picture

Hi sportel,

shouldn't be a problem to do so.
Here's a possible example (don't use as is - it's an untested dummy code ;) )

function addressfield_form_ch_postal_code_validation($element, &$form_state) {
  if (!empty($element['#value'])) {
    $autocomplete = db_select('my_table', 'mt')
      ->fields('mt', array('town', 'administrative_area'))
      ->condition('postal_code', $element['#value'])
      ->execute()
      ->fetch(PDO::FETCH_ASSOC);
    if ($autocomplete) {
    $addressfield = &$form_state['addressfield'][key($form_state['addressfield'])];
    $addressfield['locality'] = $autocomplete['town'];
    $addressfield['administrative_area'] = $autocomplete['administrative_area'];
    }
  }
}
sportel’s picture

Thank for the quick response. I'll let you know if it works.

Thanks,

Mike.

sportel’s picture

Hi das-peter,

I've tried to apply your patches, but I think the patch-files are incomplete. If I'm correct they should start with the path of the files that need to be patched. Yours don't, wich will probebly be the reason TortoiseSVN can't apply the patches. I don't know enough of patch-files to manually make the correct mods. Can you help?

Thanks,

Mike.

das-peter’s picture

Hi Mike,

I guess TortoiseSVN can't deal with these patches because they're created by git.
Has TortoiseSVN, similar to TortoiseGit, a shell prompt on Windows?
If so, you can maybe use the stand alone patch tool as described here: http://drupal.org/patch/apply

sportel’s picture

Hi das-peter,

Thanks for the help, I used TortoiseGit and that worked. Now I'm trying to figure out how to use your example for using a databasetable for autocompletion. But to be honest, I have no idea where to put it (in the original files ofcourse, not in the patched ones). Any help would be appriciated (I really should follow some php training or something).

Thanks,

Mike.

gagarine’s picture

You use "premise" as a street number. But is not the case, this field is commonly know as "address 2" (I know is confusing). The street's number is in the same field than "Street" (again I think is confusing and the label should be "Street and number" or like amazon a small help under the field).

$form['premise'] = array(
      '#title' => t('Number'),
      '#type' => 'textfield',
      '#size' => 10,
      '#required' => $required,
      '#default_value' => $address['premise'],
    ); 

I also had a hard time to applied your patch. I needed to use patch -p0 instead of the habitually -p1.

gagarine’s picture

Status: Needs review » Needs work

mmmh perhaps you right in fact. So I will say "i don't know". but a field for the number is strange for me and not really useful.

das-peter’s picture

Just took a look into the xNAL standard docs - but what I found just confuses me even more :)

Specification of the identifier of the premise (house, building, etc). Premises in a street
are often uniquely identified by means of consecutive identifiers. The identifier can be a
number, a letter or any combination of the two.

^^ http://xml.coverpages.org/XNAL-DTDs-display.html

But then there's also the element ThoroughfareNumber in http://xml.coverpages.org/XNAL-Examples-200203.html which seems to fit even better.

Besides that it looks like the usage of the premise field is quite inconsistent in the module.
Maybe DamZ can enlighten us :)

sportel’s picture

And there is even the element 'ThoroughfareNumbersuffix', for addresses like "Mainstreet 234-B", wich is quit commonly used in the Netherlands. By breaking down the address by using Thouroughfare, ThouroughfareNumber and ThouroughfareNumber the validation of the input can be made much better. Also, it'll make the use of an addressdatabase (and autocompletion) much easier.

gagarine’s picture

@sportel by breaking down you also think of the user input or only storage? I hate form with tone of field, specially because a lot of user use mouse to select field (slow).

We should be able to have one input field for street addressee like "Chemin des grottes 2b". It's not so easy to break that in different field. In USA number can be at the begining "1600 Amphitheatre Pkwy" that's all right... but what about:

"1600A Amphitheatre Pkwy"
"1600-A Amphitheatre Pkwy"
"1600 A Amphitheatre Pkwy"
"Amphitheatre Pkwy 1600 A"
"Amphitheatre Pkwy 1600.A"

Yeah user do wired thinks like that all the time...

And what if a street name is "A nice avenue" so we can have "34 A A nice avenue".

Do you think we can/should split that in different database field without any risk of mess? Perhaps we should just give the two possibility... But this is really important than we go in the same direction and I will like to have DamZ point of view too.

valderama’s picture

would be nice to see those mods and additions in the next release :)

sportel’s picture

Hi gagarine,

Thanks for your reply. It all kind of depends on what you want with your drupal-based website/webapplication. For a webapplication in a more professional environment, it would probebly be more important to have all the data, like addresses, validated, or at least as clean and uniform as possible. And in my oppinion that is only possible by breaking down the input, or at least not having a complete address input in only one field.
Further, by breaking down the input, it'll be easier to query the addresses. Like for example: select all the users in a certain city.
And, something thats important for me: in the netherlands there are databases available with all the provinces, cities, postalcodes, streetnames and numbers. It is possible to get all the right address-information from such a database by only giving the postalcode and housenumber. The rest would be autocompleted. (Thats a feature I would like to see in this module as well, and I'm busy with that, but It's hard for me since I'm really a php-noob)

BTW, your example "34 A A nice avenue" would have to be entered like:

Thoroughfare (Streetname): A nice avenue
ThoroughfareNumber (Number): 34
ThoroughfareNumbersuffix (Suffix): A

Hope this explanes my point of view.

das-peter’s picture

Patch rerolled.

das-peter’s picture

Status: Needs work » Needs review
StatusFileSize
new226.71 KB

Fixed missing comma.

das-peter’s picture

Fixed possible unnecessary line break in address formatters.
array_filter won't work as needed if not $address['name_line'] is used since there will be always a whitespace:
!empty($address['name_line']) ? $address['name_line'] : $address['first_name'] . ' ' . $address['last_name'],

Changed code:
trim((!empty($address['name_line']) ? $address['name_line'] : $address['first_name'] . ' ' . $address['last_name'])),

damien tournoud’s picture

Status: Needs review » Closed (won't fix)
StatusFileSize
new215.89 KB

The -reloaded branch has been merged. It has reasonable defaults for Switzerland. I don't believe the autocomplete is in the scope of this module.

For reference, here is how to implement this patch in the new plugin system.

sportel’s picture

Hi Damien,

I tried your address-ch.inc as an example. But I don't get any autocompletion when entering postalcode (chosen from the list in address-ch.inc). To test this add-on I made a content type with a addressfiels, with the adress form (both the country specific and the CH add-on) set as format handlers. I asume this is the correct way?

Thanks,

Mike.

Loikkk’s picture

Hi,

I would like to know if it is possible to fetch all these datas directly from Google Maps for a more flexible feature?