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) »
  • Creating a custom select field
Pages: [1]

Author Topic: Creating a custom select field  (Read 887 times)

dragontree

  • Guest
Creating a custom select field
October 22, 2009, 03:44:44 am
How can I make an advanced multiselect field so that the options are taken from the database? The options would be all the mailing list type groups.

I cant find where the options are added to the multiselect element.
I was thinking that if I find that, then I can add a little hack so the options are taken from the civicrm_groups table instead of the civicrm_option_value table...

EDIT:
I found out that in CRM/Core/BAO/CustomField.php there is a variable $selectOptions which seems to be the one I'm looking for. Not sure though...
« Last Edit: October 22, 2009, 05:17:58 am by dragontree »

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: Creating a custom select field
October 22, 2009, 08:56:08 am

check:

http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+hook+specification#CiviCRMhookspecification-hookcivicrmcustomFieldOptions

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

dragontree

  • Guest
Re: Creating a custom select field
October 22, 2009, 12:51:20 pm
Great, that's just the thing I needed. I knew there was an easier way to do this.

Thank you Lobo, you're the best


EDIT: This is the code I came up with. It works for me so I'm happy.
It populates the custom field (adv select) with "mailing list" type groups which I use for my event notification emails.
Code: [Select]
function joomla_civicrm_customFieldOptions( $fieldID, &$options ){
    if ($fieldID == '31'){
        $params=array(group_type=>2);
        $returnValues=array(id,title);
        $options = array();
        $groups = CRM_Contact_BAO_Group::getGroups($params, $returnValues);
        foreach ($groups as $group){
            foreach ($group as $key => $value){
                if ($key == 'id') $option_key = $value;
                if ($key == 'title') {
                    $option_value = $value;
                    // We dont need the values after the title
                    break;
                }
            }
            $options[$option_key]=$option_value;
        }
    }
}
« Last Edit: October 30, 2009, 06:48:33 am by dragontree »

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Creating a custom select field

This forum was archived on 2017-11-26.