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) »
  • organization field in a profile: suggestions to avoid the free form field
Pages: [1]

Author Topic: organization field in a profile: suggestions to avoid the free form field  (Read 1622 times)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
organization field in a profile: suggestions to avoid the free form field
March 15, 2011, 02:25:11 pm
Hi,

I have a profile on a registration form for an event asking among other things for the current employer.

Having a free form is a source of a lot of problems, because each participant from the same organisation is likely to spell it differently, use the acronym, prefix with the country...

For some events the list of possible organisations is predefined (eg. the members' organisations). Or mostly defined (that list, plus an option "other" and a free form).

I thought about changing the template of the form and put a drop down (or autocomplete), but

1) As the param you send when you save is the name of the organization and not the id, you will have problems with duplicates (even if you choose "ACME" id 42, if you have another ACME org in your db, it won't know that's the 42 you want as you only send ACME, so it will get all confused and create a 3rd ACME).

2) I'm likely to have different profiles willing to use that "predefined list of acceptable organizations", so rather than having the customisation at the profile level, I'd rather have it at the field level (more a feeling than an hard constraint)

3) I can't use a contact reference autocomplete, cause I want anonymous to register

I'm thinking of creating a new int custom field "predefined organisations" that is with view only/PHP

having a buildForm and create the select with option value=contact_id and name == name

and on the post hook use the id to put it into the current employee

Bit clumsy, do you have a better idea ?

X+







-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Re: organization field in a profile: suggestions to avoid the free form field
March 21, 2011, 01:48:52 pm
I had a similar need and approached it by instituting the contact autocomplete search (with my preferred query) directly on the current employer field. But I found the behavior buggy -- which at the time I attributed to my poor javascript skills.

I would prefer to see a method for approaching on those lines worked out, as eventually that's where the data will land. Ideally we re-enable the ability to do the quicksearch on current employer as an anonymous user, but pass the query through the contactListQuery hook so it can be manipulated there.

-b
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: organization field in a profile: suggestions to avoid the free form field
March 21, 2011, 02:15:55 pm
Convinced that the hook is not at the most efficient level. IMO, the best it to have an api that returns the 10 contacts that matches best the query. This can allow to go further than a single query. (eg having the list of the most common contacts if query is empty, search on like query%, then if it returns less than 10, replace by %query%...

But that for api on 4.x, that will allow to offer the access to anonymous and do smarter stuff. stay tuned.

In the meantime, not sure what's best.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: organization field in a profile: suggestions to avoid the free form field
March 22, 2011, 09:55:42 am
We're going to launch a small ($750) MIH to provide UI-based mechanism for restricting value returned by any Contact Reference custom field to a specified group. This functionality might help some of these use cases (possibly combined with a hook to create the employer relationship).

That said, it seems like Xavier's behavior for Current Employer for anonymous might be a path to solve this in core (assuming admin has the ability to decide what group of contacts to expose (if any) OR option to use existing free-form text field if they don't want to expose any existing org records.
Protect your investment in CiviCRM by  becoming a Member!

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: organization field in a profile: suggestions to avoid the free form field
March 22, 2011, 11:53:01 am
Hi,

By moving that autocomplete field to use the api instead of custom ajax backend, you can then provide a really simple tool where by changing the url you can filter.

previously bloged about it:
http://civicrm.org/blogs/xavier/how-customise-contact-reference-custom-field

So for the same amount, you could:
- Migrate the backend to be part of the api (so that quick search feature is also available for other),
- add a configuration field so you can change if you want to filter by group, tag, sub_type, group and tag and country and custom field X...)
- and be happy ever after.

X+



X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: organization field in a profile: suggestions to avoid the free form field
March 22, 2011, 12:58:58 pm
Will it help me lose weight too? And get some fab abs?
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: organization field in a profile: suggestions to avoid the free form field
March 23, 2011, 12:05:48 pm
Xavier - Makes sense to look at using the api as part of this "project" if the MIH gets funded. Can you sketch out how you think the UI might work for "add a configuration field so you can change if you want to filter by group, tag, sub_type, group and tag and country and custom field X...)". I'm a bit at loss to imagine a simple UI which does that - hence the idea of using a group as the filter (smart groups can aggregate almost any combination of the above using Adv Search UI).
Protect your investment in CiviCRM by  becoming a Member!

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: organization field in a profile: suggestions to avoid the free form field
March 23, 2011, 05:21:42 pm
A long time ago I tried to meet this need by creating an API which basically returned the contents of a search profile.

This meant that whatever fields & whatever group limitations you were prepared to expose to whatever role/ group was also available via api. ACLs can control profile access in addition to standard permissions. So, I created a search profile of a smart group of certain employers. To some extent this made what data you were exposing to whom more explicit.

Not sure if this was / is still a useful approach.
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: organization field in a profile: suggestions to avoid the free form field
March 24, 2011, 11:06:45 am
Hi,

Simple (I like simplicity)

1) Modify the template used to display the autocomplete to use an api (qsearch) instead of the custom end point, say api(contact, quicksearch). This returns json

(that's what I've done in the blog, but that's even more simple, because you don't have to undo the default autocomplete)


2) Modify the field autocomplete so you can store (somewhere, not sure where, in the option table?)  the url of the ajax api

by default, that will be "/civicrm/ajax/rest&json=1&entity=Contact&action=quicksearch"

3) the poweruser can change and replace by
/civicrm/ajax/rest&json=1&entity=Contact&action=get&group=42&country=fr&tag=123

or whatever wicked param they want

4) for the normal user, you display a list of group {crmAPI entity="Group" action="get"}, when you click on the group it (in js) generates the ajax api
/civicrm/ajax/rest&json=1&entity=Contact&action=get&group=42{idofthegroup)

and is used like for 3.

The only change outside of templates/api is offer the option to set the url api on the customfield, and save it somewhere.

X+

-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: organization field in a profile: suggestions to avoid the free form field
March 24, 2011, 02:22:35 pm
Interesting approach.  :)

I would want the ajax URL to be hidden from folks by default (they just select a group from drop-down). Power users could click a "modify filter" link to view and change the passed params.
Protect your investment in CiviCRM by  becoming a Member!

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: organization field in a profile: suggestions to avoid the free form field
March 24, 2011, 03:46:56 pm

One other thing which we should allow is the ability for an anonymous user (or non-permissioned user) to choose a contact from the list (even though this user does not have access to these contacts)

I do hope the API does not allow the above case for all contacts :)

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

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: organization field in a profile: suggestions to avoid the free form field
March 24, 2011, 03:53:57 pm
As a side note there is an MIH being launched for 4.1 to make this a UI configurable option - apparently there is $1000 remaining to be raised (which is probably less than we would have charged for the time used on this thread so far it we had been billing the discussion out)

Having said that .. Xavier's example should is not restricted to just this & reading it very carefully & understanding it is high on my to-do list!
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • organization field in a profile: suggestions to avoid the free form field

This forum was archived on 2017-11-26.