Creating an Editable Allowed values list using CCK

abelb's picture

Hi everyone,

i am looking for the best way to set up an editable amenities list using CCK.

i have a content type called Accommodations in which the admin will fill in a bunch of data to create hotel listings.

The client wants to have an amenities list that they can check the applicable amenities for the listing and then add notes to any individual amenity.
For example, one of the checkboxes would be "Swimming Pool". The user can check that the listing has a "Swimming Pool" but then have a text field next to it that they can fill out to give more detail such as: "Shallow End, Deep End, Diving Board, Slide". This text field would not be required. It is only there if the admin needs to put in extra notes.

Im not a strong coder but learning so I am not afraid of code. It just might take me a second or two. I am good at implementing modules and tweaking. can any one point me in the right direction for how to get this done?

Someone suggested Conditional Fields module. Does anyone have experience with this module? Are there any other modules you might suggest or methods of achieving this? There will be about 40 amenities in the checklist in this content type.

thanks so much for any assistance!


One brainstorm

dnotes's picture

I once tried conditional fields, and I found it overly complex and difficult - however, there's a great chance that the module has improved tremendously in the year and a half since then, so I'd recommend trying that route.

If you wanted a slightly code-heavy custom module alternative - one which takes into account that, for example, my site administrators always end up wanting to change the options immediately after I'm done coding them - I would think that you could set up a system_settings_form with a way for administrators to enter (and edit, and delete) amenities. Or you could probably use Taxonomy, which as I'm thinking about it would probably be WAY better though I'm not that familiar with it. Then you could set up a form_alter which would take each of those amenities and add it to whichever kinds of node that you want. Each item would have a checkbox and a textfield, and you could use a couple lines of jquery to make the textbox appear if the checkbox was checked. Then if you haven't used taxonomy, you'd need to store those values in a separate table - probably with a field for each amenity for fast searching, and a serialized array of text values for display? You'd have to define an additional form submit function for each node that you altered in this way. Then, if you're using views (and who isn't), you might have the task of integrating each of those fields with views for custom searches.

It's quite possible that someone has already made a module to do exactly this - take taxonomy terms and add an additional text field after them - but I'm so behind in my module knowledge I'd have no idea.

Taxonomy method

abelb's picture

Thanks for the ideas...

I am trying to wrap my head around the Taxonomy method.
So i would create a vocabulary with the terms being all of the amenities, correct?

Can you point me in the direction of a form_alter example so I can learn that? I totally know how to code a jQuery form to make the textbox appear if the checkbox is checked outside of drupal, but inside drupal im not sure where to put it.

i will need to figure that out before i move on to the rest of the tasks - storing values in a separate table and defining addtl form submit function.

it may be over my head but i want to try to figure it out.


dnotes's picture

You're on the right track. Conditional fields didn't work out for you either huh? :) I often wondered if it was just that I couldn't figure out how to use it right.

I'm not that familiar with using taxonomy in code - it has its own set of functions that do a bunch of different stuff; however, I'm sure there's a way to access all the terms in a taxonomy, etc. I once looked on for "term" and found a bunch of stuff.

For the form_alter, it really makes a difference whether you're in D5 or D6. If you go to and do a search for "form_alter" (, you can find a number of examples. Again make sure you specify which version of Drupal you're in. One important part, which may not be immediately obvious, is that you'll need to add another submit function by a line like "$form['#submit']['a_submit_function_name_you_make_up'] = array();" - that way you can add that submit function, and it will have access to all the form values so you can save them to your own db table.

By the way, I think that when you associate your taxonomy with that content type, you'll want to be able to alter the taxonomy field with your form_alter - either to add on your text fields, or to get rid of it and start over. On the off chance that the taxonomy field doesn't show up, sometimes you have to make sure that your module has a higher "weight" than some other module, like maybe taxonomy. That's just in case, but I doubt that you'd need it.

To do the jQuery using

jhedstrom's picture

To do the jQuery using Drupal, you'd want to use the #ahah element in the form api:

thanks for the info

abelb's picture

I did get conditional fields to work but it just seemed like a lot of overhead for 40 fields that i then have to have 40 conditional fields. And what you said about taxonomy made a lot of sense. That if in the future, this client wants to implement an advanced search, they would already have the amenities in taxonomy form. Plus, i have 5 other content types that have completely different amenities list and i want to find the least crufty way to do it.

I just found the Content taxonomy module and created a vocabulary of amenites' terms and pulled it in to the Content Type as Content Taxonomy Field.

I just have to figure out how to get the text field in there and then associated.

gotta some digging and learning to do. I will start with learning the form_alter.

thanks for the help. I will probably have many more questions along the way.