mlutfy / ca.bidon.regionlookup

CiviCRM extension to lookup the region of a contact depending on their postcode (or other field).
GNU Affero General Public License v3.0
1 stars 3 forks source link

Field names for state_riding and country_riding #6

Open jsnyder83 opened 7 years ago

jsnyder83 commented 7 years ago

I'm running into an odd issue where the extension will not update/post data to any field in my CiviCRM donation profile from the state_riding or country_riding fields in the database. Otherwise it is working fine.

I was able to get it working by renaming the database fields "stateriding" and "countryriding", and it worked like a charm on the profile. However, if I then attempted to the edit any of the fields directly in the database, say to correct a typo in the name of a county, then I receive the following error:

"#1054 - Unknown column 'state_riding' in 'OLD'

If I return the database field names to their original names (with the underscores), then I can once again edit the database with no problems. This isn't a huge priority, I just thought it was strange to have to choose between having a functional lookup extension on one hand, and being able editing the database on the other.

I'm hoping that this is a simple case of user error, but any help would be appreciated.

mlutfy commented 7 years ago

"if I then attempted to the edit any of the fields directly in the database"

In the civicrm_regionlookup table? What method/steps are you using to edit the data? However, I would not rename any fields, since it would require updating bits of code.

What DOM selectors are you using in your configuration? Is the form public? Can I see?

jsnyder83 commented 7 years ago

Hi Mathieu, thanks for getting back to me so quickly.

The form isn't public yet - I'm working on getting a copy running the way I want first on my localhost before I put it up on the web. I could provide you access using ngrok if that would make it easier to troubleshoot.

Here are the DOM selectors I'm using: Borough: div.crm-public-form-item.crm-group.custom_pre_profile-group input#address_custom_10-Primary City: div.crm-public-form-item.crm-group.custom_pre_profile-group input#address_custom_11-Primary State/Province: div.crm-public-form-item.crm-group.custom_pre_profile-group #state_province-Primary Country riding: div.crm-public-form-item.crm-group.custom_pre_profile-group input#address_custom_12-Primary

*** side note: Being a non-developer, I found getting the State/Province selector to work properly to be a little tricky, but I was ultimately able to update all the values in the civicrm_regionlookup "state" field to the corresponding numerical values for the states I wanted, so everything is working fine there.

Just to test things out a bit, I put a value in the "country" field in the database, and then adjusted my settings so that it would load that value into the text box I am using for the country riding (input#address_custom_12-Primary). I found that worked fine, which led me to suspect there was some kind of mismatch between the naming of the database fields (using underscores) and some bits of code (such as in RegionLookup.php as shown below)

static function getFields() { return array( 'source' => ts('Field selector'), 'district' => ts('District'), 'borough' => ts('Borough'), 'city' => ts('City'), 'county' => ts('County'), 'state' => ts('State/Province'), 'country' => ts('Country'), 'postcode' => ts('Postcode'), 'stateriding' => ts('State/Province riding'), 'countryriding' => ts('Country riding'), 'callback' => ts('Custom callback'), );

Your question about whether the form is public or not raises another interesting point. If I'm logged in as an administrator on WordPress, the CiviCRM Region Lookup extension works fine, filling in the desired fields. However, as an non-logged-in/anonymous user, the extension doesn't seem to be firing - and perhaps this is the root of my problem.

Yes, in my original question, I meant that if I try to edit a value in the civicrm_regionlookup table by double-clicking on the value and typing in a revised value, when I hit "enter" to finalize the edit, I get the error message if I've removed the underscore in the field names.