Sometimes you just need a quick solution, using the built in functionality of modules you are already using without adding extra modules to your site. For example, you might want to add a country field to a node using CCK without the overhead of a complex module like Location.
Here's an easy way, just use a standard text field, with a "Select List" widget. You then just need the data to create the options. Here's the data you need, ready to copy and paste into the options for the CCK widget.
Remember to set the maximum length of the text field to a low number (like 2) and then behind the scenes CCK will give the correct type of database field storage.
If you want a nice way to display the data in your theme head over to famfamfam and get the Flag Icons in PNG format. If you used the data above then the CCK field will output the correct country code and you just need to add ".png" on the end in your node template file to display the correct flag image.







Hi Darren, thank you for this
Hi Darren,
thank you for this article. But one question, what do you mean with:
Remember to set the maximum length of the text field to a low number (like 2) and then behind the scenes CCK will give the correct type of database field storage." ?
I never cared about low numbers in maximum field. So it's possible that some of my database field types are wrong?
Thank you!
behind the scenes...
If you just leave your CCK text fields to be unlimited length then you will get a database column with a general text type. If you specify a maximum size of 2 you get a database column with the type varchar(2). If you specify a maximum size of 25 you get a database column of type varchar(25), etc... If you don't need long text fields, then it's much more efficient to have VARCHAR type columns in your MySQL database.
So, a MySQL column of type varchar(2) is going to be more efficient than a general text column, but it's only going to store strings of length 2 or less. You probably normally need more than this, but in this example it's perfect because all the country codes are 2 characters long.
Post new comment