Author Topic: Auto-complete for organization_name in a Profile form  (Read 2075 times)

Offline scurra71

  • I’m new here
  • *
  • Posts: 18
  • Karma: 1
  • CiviCRM version: 3.3.3
  • CMS version: Drupal 6.19
  • MySQL version: 5.0.51a
  • PHP version: 5.2.4-2ubuntu5.14
Auto-complete for organization_name in a Profile form
« on: December 16, 2009, 02:01:04 am »
Hi

I want to have individuals sign up for a mailing list using a Profile form. Included in that form is an "Employee of" field which effectively links the individual to an organization. It is possible that more than one employee from an organization might want to sign up for the mailing list so I want to have the "Employee of" field be an auto-complete field (to limit the variations on the entered organization names). What is the best method to accomplish this? The mailing list form contains firstname, lastname, email address, and "employee of": is a profile form the best method for this type of sign-up?

(This topic has shown up in the forums before so I am just checking whether or not new releases have superseded older solutions.)

Thanks,
Ryan

Offline Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5016
  • Karma: 193
    • My CiviCRM Blog
Re: Auto-complete for organization_name in a Profile form
« Reply #1 on: December 16, 2009, 02:00:53 pm »
First a question. Are you ok exposing all the Organizations in your DB to users filling in this form?

Assuming yes, since an auto-complete implies that .... there still isn't a 'no assembly required' solution for this. Some things to look at:

- Use the fairly new 'Contact Reference' custom field type in the profile. But you'll need to figure out a way to filter the contacts returned to only orgs, or (better solution IMO) only contacts in a specific group/ (If you're up for implementing a patch that would allow admin to specify a 'Limit listings to group' property on this type of custom field - that would definitely be useful to the community).

- Then use postProcess hook to create the Employee / Employer relationship
Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

My faves: Relative dates in search forms and Scheduled reminders for membership renewal.

Offline Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2779
  • Karma: 137
    • Fuzion
Re: Auto-complete for organization_name in a Profile form
« Reply #2 on: December 16, 2009, 02:04:05 pm »
Hi,

I'll try to post the details soon but we have implemented this - limiting the options to a smart group.

I will try to make time tonight to post up more
Support the  MIH to consolidate CiviCRM crons (unless you are one of those rare people who never missed one). I call this the 'egg-off-the-face-MIH'

Offline scurra71

  • I’m new here
  • *
  • Posts: 18
  • Karma: 1
  • CiviCRM version: 3.3.3
  • CMS version: Drupal 6.19
  • MySQL version: 5.0.51a
  • PHP version: 5.2.4-2ubuntu5.14
Re: Auto-complete for organization_name in a Profile form
« Reply #3 on: December 17, 2009, 12:18:14 am »
Dave, Eileen

Thanks very much for the response. Yup, exposing org names is okay. I'll run the suggestions by my colleague (who is an experienced PHP developer) and await Eileen's follow-up post.

Regards,
Ryan

Offline Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2779
  • Karma: 137
    • Fuzion
Re: Auto-complete for organization_name in a Profile form
« Reply #4 on: December 17, 2009, 04:34:11 am »
HI,

I hope to find time to explain this (maybe a blog) but in the meantime I'll just get the code I'm using up:

Some of the background is here:

http://civicrm.org/node/528

You need to backport this patch. http://issues.civicrm.org/jira/browse/CRM-4637 - as at 3.0.2 the listings.php patch wasn't required.

I will post more soon - when I get a chance.

Basically in the example given it does a REST call to the new API using this URL:

{crmURL p='civicrm/ajax/rest/profile' q='fnName=civicrm/profile/search&json=1&gid=5&sort=sort_name' h=0}"{literal};

gid is the number of  a civiCRM profile with and the profile is limited to a specific group. I'll try to get time to flesh this out
Support the  MIH to consolidate CiviCRM crons (unless you are one of those rare people who never missed one). I call this the 'egg-off-the-face-MIH'

Offline scurra71

  • I’m new here
  • *
  • Posts: 18
  • Karma: 1
  • CiviCRM version: 3.3.3
  • CMS version: Drupal 6.19
  • MySQL version: 5.0.51a
  • PHP version: 5.2.4-2ubuntu5.14
Re: Auto-complete for organization_name in a Profile form
« Reply #5 on: December 18, 2009, 01:11:43 am »
Thanks very much Eileen. I'll give this a try -- or get my php-enabled colleague to.

Offline Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2779
  • Karma: 137
    • Fuzion
Re: Auto-complete for organization_name in a Profile form
« Reply #6 on: December 18, 2009, 01:22:42 am »
Good luck - it will make a lot more sense when I can write to explain but the lead up to Xmas is pretty mad!
Support the  MIH to consolidate CiviCRM crons (unless you are one of those rare people who never missed one). I call this the 'egg-off-the-face-MIH'

Offline Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2779
  • Karma: 137
    • Fuzion
Re: Auto-complete for organization_name in a Profile form
« Reply #7 on: January 06, 2010, 02:23:53 am »
I've written it - but you might be sorry you asked :-)

http://civicrm.org/node/685

Try working backwards from the summary at the end & post any questions here or on the blog.
Support the  MIH to consolidate CiviCRM crons (unless you are one of those rare people who never missed one). I call this the 'egg-off-the-face-MIH'

Offline scurra71

  • I’m new here
  • *
  • Posts: 18
  • Karma: 1
  • CiviCRM version: 3.3.3
  • CMS version: Drupal 6.19
  • MySQL version: 5.0.51a
  • PHP version: 5.2.4-2ubuntu5.14
Re: Auto-complete for organization_name in a Profile form
« Reply #8 on: February 16, 2010, 12:52:37 am »
Thanks very much Eileen, and sorry about the late reply. The project fell off the radar for a bit but now it's back in focus.