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 (Moderator: Dave Greenberg) »
  • Custom Fields in Custom Search
Pages: [1]

Author Topic: Custom Fields in Custom Search  (Read 667 times)

bpmccain

  • I post frequently
  • ***
  • Posts: 255
  • Karma: 5
  • CiviCRM version: 4.1
  • CMS version: Drupal 7.12
  • MySQL version: 5.2
  • PHP version: 5.2
Custom Fields in Custom Search
February 22, 2012, 11:10:19 am
I'm developing a custom search, and the one part I can't figure out is how to include a custom field in the form. We have a custom field composed of about 50 items accessible via a select menu. I can see how to do it for something in the Core by looking at examples:

Code: [Select]
$stateProvince = array('' => ts('- any state/province -')) + CRM_Core_PseudoConstant::stateProvince( );
        $form->addElement('select', 'state_province_id', ts('State/Province'), $stateProvince);

but what about for custom data?

Brian

bpmccain

  • I post frequently
  • ***
  • Posts: 255
  • Karma: 5
  • CiviCRM version: 4.1
  • CMS version: Drupal 7.12
  • MySQL version: 5.2
  • PHP version: 5.2
Re: Custom Fields in Custom Search
February 22, 2012, 12:34:39 pm
Never mind, I figured it out.

Code: [Select]
$name = CRM_Core_OptionGroup::values( 'option_group_name', false );     
        $form->addElement('select', "name", 'Title', $name);

andersiversen

  • I post occasionally
  • **
  • Posts: 76
  • Karma: 1
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 7.26
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
Re: Custom Fields in Custom Search
August 02, 2012, 12:48:00 pm
Hi bpm

I'm having the same problem you did, but I cannot figure out what you figured out - even with your solution right there. Maybe you can elaborate a bit.

I have a custom field defined for the subtype "Student" which I would like to include in the form - it's a multiple select menu, like in your case.
Usually when accessing custom fields in the code, I would call it with something like "custom_28" where 28 is the id of the custom field.
From your example I have no idea of which things to exchange with my own variables.
I would be very happy if you could tell which of them to change; 'option_group_name', "name"?

Thanks in advance for any help

andersiversen

  • I post occasionally
  • **
  • Posts: 76
  • Karma: 1
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 7.26
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
Re: Custom Fields in Custom Search
August 02, 2012, 02:52:34 pm
Allright I found the option_group_name by searching the civicrm database for option_group_name, and got it to work.

In my case i had a costum field wich was of the "multiple choice"  type. The name of it was "Cancelled/sick".
In the database the name was stored as "cancelled_sick_20111014164402" where all the numbers seems to be the exact date and time of when the field was created.

How does a normal human being find that name?? :)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM (Moderator: Dave Greenberg) »
  • Custom Fields in Custom Search

This forum was archived on 2017-11-26.