I found the bug in cck_address.module:

In line 333 the length should be 64 instead of 2 to support the full country names when "use abbreviations for display of countries" is unchecked. i.e. the line should be:

'country' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => "''", 'sortable' => TRUE), 

Note that if you already have cck address fields defined in some content types, you should delete the fields in the content type admin screen and recreate them OR (when you already have content submitted) change the field length in the database in the table of this content type (table content_type_YourContentTypeName) and complete the full country names for the content items already submitted (currently, you will find in this field only the first 2 chars)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rconstantine’s picture

Category: bug » support
Status: Active » Closed (works as designed)

That's not a bug. When a country is displayed, the stored abbreviation is compared to the cck_address_countries table where the full country name is retrieved. It doesn't make sense to store more data than is necessary. If you are saying that when viewing a node where the address is supposed to display the full country name that it's not, then the error lies in retrieving the full name, not in the storage per se.

In my installations, I'm having no problem with the display of the full country names during a node view.

ekrispin’s picture

See the content of this database field for yourself and see the code - The country name is trancated into 2 chars plain simple.

rconstantine’s picture

FileSize
3.3 KB

It would seem you didn't listen to what I said. Line 333 has to do with STORAGE, not DISPLAY. My screen shot clearly shows no issue with the DISPLAY of the country. The country name is not "truncated" as you say it is; rather, it is stored as a two letter code which is converted to full text at display. That's really not hard to understand. I'm not sure what you aren't wrapping your head around that. I didn't neglect to test this after your first post. I double checked that everything was as I said it was.

JacobSingh’s picture

Status: Closed (works as designed) » Postponed (maintainer needs more info)

Hi rconstantine,

Please don't be agitated, you seem quite angry, but I ran into the same issue and it cost a client 4hrs of data entry, so I thought I'd share with you my ideas.

I understand your point, and I looked at the code after this happened and realized the same. The problem is, there should be a separation between the functionality for state selection and simple data entry. In my case, the client needed to enter the addresses of branches of their organization in over 130 countries! After spending 4hrs on this, they (and I) realized that while the field is a text field with no char limit , the database was only storing the first two chars. This is not good validation or usability, plus it cripples the module for people not putting in an address from the US or Canada. Since every country in the world is not going to get a custom extension module for this, how about it I write something which will put every known iso code and country name in the aforementioned table upon installation and then provide only a dropdown instead of a text box?

Does this sound reasonable?

Best,

Jacob

rconstantine’s picture

I wasn't angry ;-), I just thought that comment #2 assumed I hadn't actually verified the operation, and I may have been having a bad day.

What you are addressing is actually a different issue. The original post clearly has to do with a complaint regarding the checkbox for "use abbreviations for display of countries", which I think I addressed. But what you bring up are valid points that I hadn't considered since I have not had the needs that you have had.

So I think an add-on module, which would be added to the address extension project that simply registers to the database all country codes and replaces the text field with a drop down would be a great idea. Of course, such a module would not follow the pattern of the others and so you'd be on your own in figuring it out. I would, however, be happy to look over any code you come up with and give advice. I just don't have time right now to write it myself. It should be a simple matter of an include file with the SQL queries filling the cck_countries table, an install file to cleanly call the include file and clean up everything at uninstall. Then simple hook_form_alter the form when both your module is installed and other countries are allowed.

If form_alter won't work, feel free to create a patch for the main module. Just make sure to switch between text field and drop down appropriately. And speaking of the text field, I suppose I should change it to 2 characters and indicate that it expects a country code if that is what I'm validating/storing there. Thanks for clearing that up for me.

You know, perhaps I would include your module with this one, rather than with the extension modules. It seems a closer fit, don't you think? Let's leave the extension project to include only sub-modules for specific countries.

Good luck!

rconstantine’s picture

If JacobSingh doesn't post a patch/contributed module, I may just mark this as 'by design' since I have no personal use for all countries in the world and have too much on my plate already. I'll give him a few weeks to respond.

JacobSingh’s picture

Heh, I've got something working on my box, I'll spend 20minutes today cleaning it up, and then submit it for review, k?

Best,
Jacob

JacobSingh’s picture

Status: Postponed (maintainer needs more info) » Needs work
FileSize
30.11 KB

Hi rconstantine,

Hope this does the trick. I'm sure the install file is not put together properly. I've never actually written one, and while I understand how it works, I'm having a hard time anticipating the problems that might arise. Please spend 10minutes to review this from your perspective of knowing the mod since inception.

Also, I assume this conflicts with the country specific modules. Should we notify the authors to update theirs are remove the country code inserts? I removed the US one from the cck_address_states.inc module already.

Best,
Jacob

rconstantine’s picture

I'll review this and let you know what I think. Depending on what things look like, I may ask you to make changes, or I may just do them myself depending on time. There's a simple method of checking whether a value exists prior to trying to insert it, so I don't think that any other module will need to be restricted from inserting its own country codes. All modules will just have to adopt a check-before-insert approach.

Actually, I just thought of another approach involving checking module existence instead of db entries. Hmm....

Anyway, thanks for the post.

BTW, is this patch against the new version?

rconstantine’s picture

Title: Country filed is truncated to 2 chars even if "use abbreviations" is unchecked » Country list patch

I keep forgetting about this

JacobSingh’s picture

Yes, patch is against dev.

sbandyopadhyay’s picture

I am working on achieving the same intended functionality as the patch off of the more recent code. From what I have so far, this looks like a fantastic feature for sites with international scope that can't define each and every country.

shooommmm’s picture

Hi Everyone,

I am new to Drupal. I've just installed Drupal 5.7 with cck_address.

I notice Jacob Singh has a patch with the complete county list.

I want to know what is the best module and/option for me to us that can list all the countries in the world with the drop down menu for user to select when registering on a site ?

Is CCK_Address the choice ? If yes, can you tell me how and where to apply Jacob Singh's patch ?

Thanks,

Hanly

sbandyopadhyay’s picture

Jacob Singh's patch is on an older release. I made a bunch of adjustments beyond Singh's code to the newest release and re-rolled the patch. I wish I'd kept better notes on what changes I made, but sadly I didn't. Anyway, this patch is against 5.x-2.1.

Hanly: yes, cck_address is perfect for what you are looking to do, once you apply this patch. You can use this patch against 5.x-2.1.

shooommmm’s picture

Hi sbandyopadhyay,

Thanks for your patch.

I got this error after applying the patch (could be my fault though).

Parse error: syntax error, unexpected ',', expecting ')' in /home/newmill/public_html/sites/all/modules/cck_address/cck_address.module on line 402

I have fixed the extra ,, in line 402.

Thanks again for your help.

Hanly

sbandyopadhyay’s picture

Hmm that's odd... just to make sure we're on the same page, do you remember what was on the rest of line 402? I didn't have anything like that in my file when I created the patch....

Anyway, how is it working for you Hanly? This patch seemed to have worked well for Jacob Singh back in the day on an older version, it's working well for me so far, and if it works well for you too, then that's definitely a good sign. Perhaps with some further testing, this patch can make it into the next release...!

shooommmm’s picture

Hi sbandyopadhyay,

I got this error when I try to edit the address field:

warning: preg_match() expects parameter 2 to be string, array given in /home/newmill/public_html/includes/bootstrap.inc on line 670.
warning: preg_match() expects parameter 2 to be string, array given in /home/newmill/public_html/includes/bootstrap.inc on line 670.

Thanks for your help,

Hanly

sbandyopadhyay’s picture

I have no idea if this helps, but check out: http://drupal.org/node/214125

I was having the exact same error there. It is for a different module, though. I don't think CCK Address is giving you the error. In any case, install the devel module, and use it in the way I outline on that link above. It should help you isolate the problem. It's probably that two of your modules don't interact with each other very nicely....

sbandyopadhyay’s picture

Steps to solve this:
1) Find and install the "devel" module.
2) Turn on "backtrace" under error logging.
3) Go to the page that gives you the warning: preg_match() expects parameter 2 to be string, array given in /home/newmill/public_html/includes/bootstrap.inc on line 670 error
4) Analyze the paramaters that are fed into preg_match() in the error readout, compare them to the standard parameters at php.net/preg_match. You will find that parameter 2, surprise surprise, is NOT a string. We all know that much from warning: preg_match() expects parameter 2 to be string, array given in /home/newmill/public_html/includes/bootstrap.inc on line 670. I think it will probably be an array of strings.
5) Trace that particular array of strings back through your code, one function at a time-- backtrace makes this easy for you, since the printout is in reverse chronological order. Where did the array of strings come from? Chances are, whereever it came from, the multiplicity of strings wasn't necessary. You can safely comment out the line in your code that was responsible for it.

I can't help you out more than that-- this depends on the modules you have installed, the configurations you have, etc.

shooommmm’s picture

Hi sbandyopadhyay,

Thanks for trying to explain to me how you would go about tracking "coding" issues.

Sadly I have almost zero knowledge of php. And don't even know where to start. I had a look at line 670 in the www/includes/bootstrap.inc which says return (preg_match('/^./us', $text) == 1);

I don't know where to go from here?

Well, can you tell me if this error is due to the cck_address or another module which have no clue about:
warning: preg_match() expects parameter 2 to be string, array given in /home/newmill/public_html/includes/bootstrap.inc on line 670.

So I can then file a request for support at the appropriate module instead of wasting your time here.

Thanks,

Hanly

sbandyopadhyay’s picture

You should learn PHP. It's not that difficult. I knew zero PHP just a year ago, now I know enough to custom code some changes to Drupal. You can start here: http://www.w3schools.com/php/default.asp

Line 670 in bootstrap.inc will not help you. As I have said in my last two posts, the error that you are getting usually happens (based on my experience, at least) when two contributed modules conflict with each other in some way. It could be cck_address (post-patch, I imagine-- this patch isn't perfect yet, after all, what we should be doing on this thread is debugging the patch), or it could be something else. Unless you know some PHP and can isolate the problem using the method from my previous post (which really shouldn't be too hard to follow... it doesn't require extensive knowledge of PHP), there's no real way for us to help you.

...

In other news, this patch is working well for me so far. It'd be great to see others who need this functionality test it, and see if all's working well with them too.

rconstantine’s picture

FYI, I'll be getting to this module after updates to CCKTSSU and og_forum.

doctorpaul’s picture

newbie question

what is a PATCH?

what do you actually DO with a patch?

I'm guessing that I would copy it as a .txt file and then upload it to the cck_address module folder?

Do I have to RUN something once its there? Sorry - but I just don't know what do with it....

#####################################

incidentally: what I'm trying to achieve:

I want the country field to be the ONLY field from cck_address that my users choose from on the particular node type I'm building.
And I want them to have the choice of all countries in the world.

I have installed cck_address module but it only seems to give me the choice of the USA! Have I got it set up wrong or does the module really only have USA in the list? Whilst I appreciate the relative strength and importance of the USA as a nation, particularly since 1945, there around 200 other places my users might come from!

If it's a Drupal module - shouldn't Belgium be in there at least?

Is there a simpler way to get the functionality I'm looking for?

ron_s’s picture

A patch is a small file that adds and removes lines of code from a module to make adjustments to it. There are programs available that allow you to apply a patch directly to a module, or you can even do it manually. If you open the patch file it's quite straightforward ... each change is denoted with a "+" for lines added and a "-" for lines removed, and tells you where in the files the changes are made (which file name, which function, which approximate line in the code).

CCK address provides a framework for adding more countries, states, provinces, etc., but doesn't automatically come with all of them included. The patch in this thread allows for the addition of other countries, but has no validation against states/provinces. So for example, if you wanted Germany plus the provinces of Germany, you'd need to add this yourself. If you just want Germany as a country and not interested in the provinces, then the patch on this thread does the trick.

If you're *only* planning to use country and have no use for the other CCK address fields now or in the future, why not just create a simple select option using CCK Select instead of using this module? Call it "Country" and put all the countries in the available options.

doctorpaul’s picture

hey ron - than you so much for explaining patches - that makes my life today just that wee bit clearer than it was yesterday. If you keep doing stuff like that for people like me, you'll get to heaven*

thanks

Paul

*if it exists

NewZeal’s picture

Status: Needs work » Closed (fixed)

Issue older than six months and now solved by using country_select and activeselect.