1

I'm trying to create a content type that has multiple countries available to be selected and then multiple states/territories within those countries based on the country, but I'm not sure how to best accomplish this.

When a user is creating a piece of content they need to be able to select their country, then based on the country they select, they can select their state or territory with only those states/territories for that country available as options. I have two such countries that will have multiple states/territories - the U.S. and Canada.

I'm creating a text field using the field module that lists all the U.S. states when a parent item is selected using a list (text) and a "select text" drop-down. I also need to create a way to present the user with the Canadian territories when selecting Canada as the territory.

Right now I have two fields - "Country" and "State". Can you recommend the best way to accomplish presenting the user with the correct options for the state/territory based on their country selection? I'm drawing a blank on this one.

2 Answers 2

1

In Drupal 7 you should use the dedicated addressfield module for that purpose.

The composite address field provides a country drop down box with other address fields such as state loaded via ajax depending on the selected country.

USA

Addressfield USA

Canada

Addressfield Canada

It's a requirement of the Commerce module for address selection.

You can hide some of the address sub-fields if needed.

1
  • I'm working on this using the addressfield module you suggested and I'm curious how to hide the "address 1 & 2" fields when adding a node?
    – Rob Orr
    Commented Jan 21, 2013 at 19:13
0

Probably two text fields with widget select, and use form #ajax to update the region list when the country is selected. See Dynamic select list in the form (dependent dropdown) for a similar answer.

Another option might be Hierarchical Select which does this "out of the box" - you could use a vocabulary for the country/region structure. Consideration here is that you'll need to look up the parent term of the region to find the country, and maybe you'd rather have an easy way to query "content from Canada" than "content from any region which has a parent term of Canada".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.