CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Profiles (Moderator: Dave Greenberg) »
  • state/province not working with profiles in 4.4.4
Pages: [1]

Author Topic: state/province not working with profiles in 4.4.4  (Read 1284 times)

carlitos

  • I’m new here
  • *
  • Posts: 25
  • Karma: 1
    • International Council for Traditional Music
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 6
  • MySQL version: 5
  • PHP version: 5
state/province not working with profiles in 4.4.4
March 30, 2014, 05:54:46 am
Dear all,

A very involved profile I have, which updates most contact fields (both core and custom) used to work OK with state/province  information, for both viewing and updating. After upgrading to 4.4.4, that field doesn't seem to be noticed by profiles anymore.

I've trying removing all customisation from that particular profile (both code/ and templates/), and creating test profiles from scratch only having country and state, but not a single profile is now able to neither display nor edit properly the state/province information which is, by the way, properly stored in the database.

I realise that something similar was detected in 4.1 (http://forum.civicrm.org/index.php/topic,30737.msg131861.html#msg131861), but I'm updated to 4.4.4. Maybe there was a regression?

Of course, editing contacts via the regular Edit screen works OK -- it's just the profiles which don't work.

This profile is the basis of a new feature for the members of our non profit NGO (a membership directory), and I can't break the news unless the State information can be updated properly.

Thanks a lot in advance for any help you can give.

Best,

Carlos

carlitos

  • I’m new here
  • *
  • Posts: 25
  • Karma: 1
    • International Council for Traditional Music
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 6
  • MySQL version: 5
  • PHP version: 5
Re: state/province not working with profiles in 4.4.4
March 30, 2014, 06:22:29 am
I forgot to say, when I say that State/Province is not being 'noticed', I mean that profileFields["state_province_Primary"] comes always empty.

I'm thinking of using the API to fill this myself, but the problem still exists...

Hope this helps with the diagnosis, doctors :)

Carlos

joanne

  • Administrator
  • Ask me questions
  • *****
  • Posts: 852
  • Karma: 83
  • CiviCRM version: 4.4.16
  • CMS version: Drupal 7
Re: state/province not working with profiles in 4.4.4
March 30, 2014, 07:05:40 am
The patches here may help.  http://issues.civicrm.org/jira/browse/CRM-14198  - although maybe not as this was for problems exporting states.
« Last Edit: March 30, 2014, 07:09:18 am by joanne »

carlitos

  • I’m new here
  • *
  • Posts: 25
  • Karma: 1
    • International Council for Traditional Music
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 6
  • MySQL version: 5
  • PHP version: 5
Re: state/province not working with profiles in 4.4.4
March 30, 2014, 07:57:16 am
Thank, joanne. Unfortunately it didn't fix my problem. Will keep looking...

carlitos

  • I’m new here
  • *
  • Posts: 25
  • Karma: 1
    • International Council for Traditional Music
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 6
  • MySQL version: 5
  • PHP version: 5
Re: state/province not working with profiles in 4.4.4
March 30, 2014, 11:17:55 am
After poking around Core for a while, I found a solution to my problem.

Since we can use the API to properly return state_province_id, I did the two following edits (to cover View and Edit operations), and the problem was solved.

In my overridden copy of CRM/Profile/Form.php, at line 509, just before the foreach statement, I added:

Code: [Select]
if ($this->_gid = 1) {
  /*
  30-Mar-2014
  In CiviCRM 4.4.4, state_province information is lost to Profiles.
  So, we have to look it up via the API, and inject it into $defaults, until a proper fix is found
  */
  $contact = civicrm_api("Contact","get", array ('version'=>3,'id'=>$this->_id));
  if ($results["is_error"] == 0) { 
    $this->_defaults["state_province-Primary"] = $contact["values"][$contact["id"]]["state_province_id"]; // 1004
  }
}

(my big profile's ID is 1)

In my overridden copy of CRM/Profile/Page/Dynamic.php, at line 330, just before the assignment of vars 'row' and 'profileFields' to the template, I added:

Code: [Select]
if ($this->_gid == 1)
{
  /*
  30-Mar-2014
  In CiviCRM 4.4.4, state_province information is lost to Profiles.
  So, we have to look it up via the API, and inject it into profileFields, until a proper fix is found
  */
  $country = null;
  $state_province_id = null;
  $region_id = null; // used later in city-line styling

  $contact = civicrm_api("Contact","get", array ('version'=>3,'id'=>$this->_id));
  if ($results["is_error"] == 0) { 
    $state_province_id = $contact["values"][$contact["id"]]["state_province_id"]; // 1004
    if (!empty($state_province_id))
    {
      $q = 'SELECT a.region_id, a.is_province_abbreviated, b.name as state_province_name, b.abbreviation as state_province_abbr FROM civicrm_country a inner join civicrm_state_province b on a.id=b.country_id WHERE b.id='. $state_province_id;
      $res = CRM_Core_DAO::executeQuery($q);
      $res->fetch();
      $region_id = $res->region_id; // saved for later construction of city-line

      if ($res->is_province_abbreviated) {
        $profileFields["state_province_Primary"]["value"] = $res->state_province_abbr;
      }
      else {
        $profileFields["state_province_Primary"]["value"] = $res->state_province_name;
      }
    }
  }
}

This last chunk of code also displays state abbreviations, for those countries who use them (USA, Brazil, Australia, Canada, etc). You can ignore it if you don't need it, and stick to just setting $profileFields["state_province_Primary"]["value"] to $state_province_id.

Now, would this be (roll thunder) A Bug? Would the forum gods and goddesses step in, please? :)

I'm very happy I worked this out myself, but if you have any suggestions to make my code better, I'm all ears. I'm a veteran web builder (C#, Python) but a total PHP rookie.

Hope this helps someone with similar issues!

Carlitos

spalmstr

  • I post occasionally
  • **
  • Posts: 44
  • Karma: 2
  • CiviCRM version: 4.5.4
  • CMS version: Joomla! 3.3.6 Stable [ Ember ] 01-October-2014 02:00 GMT
  • MySQL version: 5.6.21
  • PHP version: 5.6.0
Re: state/province not working with profiles in 4.4.4
June 27, 2014, 02:50:32 am
Has a fix been supplied?

carlitos

  • I’m new here
  • *
  • Posts: 25
  • Karma: 1
    • International Council for Traditional Music
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 6
  • MySQL version: 5
  • PHP version: 5
Re: state/province not working with profiles in 4.4.4
June 27, 2014, 02:54:54 am
To my knowledge, no.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Profiles (Moderator: Dave Greenberg) »
  • state/province not working with profiles in 4.4.4

This forum was archived on 2017-11-26.