5

I'm new using Drupal, and I'm trying creating a database driven website in Drupal. I don't know what is the best way of doing the following:

I need to have three types of 'entities' (content types):

  • Worker
  • City
  • State

Every Worker lives in one and only one City, and every City is in one and only one State.

I could create those three contet types:

  • State
  • City, that will have a node reference to State
  • Worker, that will have a node reference to City

But...

When I someone creates a new Worker, I don't want Drupal to show a list with all the cities (because there could be cities with the same name in different states).

How could I add the feature of selecting first the State, and then the City, when creating a new Worker, or something like that that allows the user to differentiate?

Edit:

The module Dependent Fields would work in this case, but it forces me to add another field to the Worker content: A State. I don't want this, because it could be kind of redundant information (knowing the city of the worker, I can also know the state). Do you know what I mean?

  • Looking back at your original info, why are you making content types for city and state? Will they contain a lot of extra information and fields? It isn't really necessary if each will contain nothing more than a name. – davidhernandez Mar 27 '11 at 16:04
  • @David State doesn't contain any more info, but I need to include more fields in the City content. – Oscar Mederos Mar 27 '11 at 18:17
  • @David Anyway, what would you suggest? – Oscar Mederos Mar 27 '11 at 18:21
  • It sounds like you could use just two content types. One for worker and one for locations (containing city and state). – davidhernandez Mar 29 '11 at 12:49
5
+25

I would create a taxonomy hierarchy that has nested State -> Cities. You can then provide a way for them to choose a state, and filter a drop-down by the parent taxonomy.

Hierarchical Select will do this for you.

If you need to create a content type for city, just apply the same taxonomy term to link the two together.

Kim

  • I agree with this approach. If you were using Drupal 7, you could add fields to the taxonomy terms... – tim.plunkett Mar 29 '11 at 3:37
  • Agreed on all counts, hierarchical select is exactly what you are looking for! – Alex Weber Apr 1 '11 at 13:04
2

Sounds like the Conditional Fields module might help. This allows you to make CCK fields that are dependent, so you can choose State and then get City.

Some more details about this module (from its project page):

Conditional Fields allows you to manage sets of dependencies between fields. When a field is “dependent”, it will only be available for editing and displayed if the state of the “dependee” field matches the right condition.

When editing a node (or any other entity type that supports fields, like users and categories), the dependent fields are dynamically modified with the States API.

You can, for example, define a custom “Article teaser" field that is shown only if a "Has teaser" checkbox is checked.

1

What about using the Postal module? I could use some help developing it.

1

I found this - http://drupal.org/node/626088 - Hierarchical Select Node Reference.

It sounds exactly like what you were originally intending. Looks a bit complicated to setup.

0

I think you should to use taxonomy for State & City with multilevels? After use hierarchical_taxonomy module.

Enjoy ;)

0

what about making diferent entitys . you can use eck http://drupal.org/project/eck one entity for state , and another one for city. then you could use relation (http://dev.nodeone.se/en/learn-the-relation-module) o maybe entity reference (http://dev.nodeone.se/en/using-the-reference-modules). then you createa field in user acount or in the content type that you have made that refers them .

you could use display suit (http://www.youtube.com/playlist?list=PL7E361A55994F1648) , field group http://www.youtube.com/watch?v=vhA5b5KpHZw and Renderable elements (http://www.youtube.com/watch?v=rSgd91tZSEc), this crate a mutipage content types

good luck.....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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