Support (offered by community volunteers) > Using CiviCRM

Custom Fields in Custom Search

(1/1)

bpmccain:
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: ---$stateProvince = array('' => ts('- any state/province -')) + CRM_Core_PseudoConstant::stateProvince( );
        $form->addElement('select', 'state_province_id', ts('State/Province'), $stateProvince);
--- End code ---

but what about for custom data?

Brian

bpmccain:
Never mind, I figured it out.


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

andersiversen:
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:
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?? :)

Navigation

[0] Message Index

Go to full version