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) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Hyphens in Custom Field multiple choice values
Pages: [1]

Author Topic: Hyphens in Custom Field multiple choice values  (Read 2073 times)

davo

  • Guest
Hyphens in Custom Field multiple choice values
February 22, 2008, 07:53:18 pm
I needed a custom field, a drop-down list, with many values. Rather than create it manually I wrote a simple PHP script to create it for me. I used crm_create_custom_group to create a custom group, then crm_create_custom_field to create the custom field of data_type => String and html_type => Select within that group. And finally, I used crm_create_option_value to add the custom values to the field. I used strings like "AA-1", "AA-2", etc. for the values and "All Age 1", "All Age 2", etc. for the labels. The creation worked fine. The custom field previewed correctly and went into production. Users were able to modify the field value for their accounts with no trouble.

Then I had needed to change one of the labels. So I went to edit it through the CiviCRM GUI. When I went to save my changes, the GUI prevented the change on the grounds the value (not the label) contained a hyphen (-). The full error message was:
Quote
Please correct the following errors in the form fields below:

    * Please enter a valid value for this field. You may use a - z, A - Z, 1 - 9, spaces and underline ( _ ) characters.

So I now have a problem. Many users now have the value containing the hyphen stored in their database record. If I simply update the value in the GUI, it will be out of synch with what's stored in the database. This will be tricky to resolve. I presume I'll have to modify the database directly.

The underlying issue is that API has let me use a hyphen, but the GUI does not. In my view this difference needs to reconciled in the code. What do others think?

Interestingly, most browsers seems to cope with the hyphen just in the HTML. Looking at the HTML 4 standard it seems that a hyphen might be permitted. In which case the GUI code is the one that needs to change.

PS: I'm using CiviCRM 1.9.x.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Hyphens in Custom Field multiple choice values
February 23, 2008, 12:47:48 am

1. our api's dont do as much checks as the forms. I suspect this happens in a few other cases. Our api support is not very strong (IMO)

2. Please file an issue and we'll fix in 2.x. Highly likely we will stick to the current form rule and add the check to the api. You can do a str replace in your db. I'm also pretty sure when you change the value, we go in and fix the custom_value table.

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

davo

  • Guest
Re: Hyphens in Custom Field multiple choice values
February 24, 2008, 04:46:40 pm
Quote
1. our api's dont do as much checks as the forms. I suspect this happens in a few other cases. Our api support is not very strong (IMO)
Fair enough. Perhaps this could be an area for 2.1 to improve on. From an architecture/design point of view, the API and GUI should use the same validation code. Of course, implementing this is another question :)

Quote
2. Please file an issue and we'll fix in 2.x. Highly likely we will stick to the current form rule and add the check to the api. You can do a str replace in your db. I'm also pretty sure when you change the value, we go in and fix the custom_value table.
OK. I'll file an issue. Should it be a general one to check all API vs GUI validation? Or just stick to this one small case?

Further, when I did update the value, a user who had selected the old value now showed as not having selected anything. This suggests to me that changing the value does not include changing existing uses of the value already in the DB.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Hyphens in Custom Field multiple choice values
February 24, 2008, 05:42:18 pm

1. The amount of folks using / exercising the api's is significantly small. We got absolutely no replies for our prior feedback post at: http://www.nabble.com/Feedback-Needed-on-Future-API-Development-td12892088s15986.html#a12892088 . As such it makes it hard for us to spend any significant amount of time on it when the return is pretty minimal

2. If you are willing to step up and drive CiviCRM api development that would be great :) I'm coming to the conclusion that mixing a procedural api with our OO model does not make a lot of sense and we should just expose / standardize on our OO model and get people to code against that. Since internally we dont use the procedural api, it is not well exercised / tested etc and as such potentially has some bugs (general laws of software development :(

3. Please file an issue for the small case only.

4. For your final bug, can you please test against the 2.0 code base. If still present in 2.0, please file an issue

lobo


A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Hyphens in Custom Field multiple choice values

This forum was archived on 2017-11-26.