Answers.Body: <p>As I haven't seen your code, I can only suggest what worked for me:</p>
  
  <pre><code>function myext_civicrm_fieldOptions($entity, $field, &amp;$options, $params) {
  
    if ($entity == 'Contribution') {
      if (isset($field) &amp;&amp; $field == 'mycustomfield_123') {
        $myArray = [
          1 =&gt; 'Title 1',
          2 =&gt; 'Title 2'
        ];
        $options = $myArray;
      }
    }
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-27T11:55:00.717Z
Answers.Text: Hi mate, thanks this has worked if i associate it with a field on the contrubution form but when i try to link to a custom field for e.g. custom_276_-1. Nothing happens
Answers.UserDisplayName: Moe
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-27T12:06:37.503Z
Answers.Text: @Moe try to set $field == 'custom_276'
Answers.UserDisplayName: VangelisP
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-27T12:23:26.010Z
Answers.Text: That worked! Thank you very much! I need more things to get to my end goal but this really helped.
Answers.UserDisplayName: Moe
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-27T11:21:56.970Z
Answers.LastActivityDate: 2019-11-27T11:21:56.970Z
Answers.UserDisplayName: VangelisP
Body: <p>I have a "Select list" within a Contribution Form. I want to populate the "Select List" with Custom Field values.</p>
  
  <p>I have created the Custom Group under Contacts, so i want to search all contacts and get the custom field "Title" from that Custom group.</p>
  
  <p>Then depending on the "Option" selected i want field values to populate. </p>
  
  <p>I have tried to use the:</p>
  
  <p>hook_civicrm_fieldOptions but its not working (<a href="https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_fieldOptions/" rel="nofollow noreferrer">https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_fieldOptions/</a>).</p>
  
  <p>Any advise on how to do this?</p>
  
  <p>Thanks</p>
  
  <p>This is the HTML for field i want to populate:</p>
  
  <pre><code>&lt;tr class="custom_field-row custom_276_-1-row"&gt;
      &lt;td class="label"&gt;&lt;label for="custom_276_-1"&gt;Proc Fee&lt;/label&gt;
        &lt;a class="helpicon" title="Proc Fee Help" aria-label="Proc Fee Help" href="#" onclick="CRM.help(&amp;quot;Proc Fee&amp;quot;, {&amp;quot;id&amp;quot;:276,&amp;quot;file&amp;quot;:&amp;quot;CRM\/Custom\/Form\/CustomField&amp;quot;}); return false;"&gt;&amp;nbsp;&lt;/a&gt;    &lt;/td&gt;
      &lt;td class="html-adjust"&gt;
        &lt;div class="select2-container crm-select2 crm-form-select" id="s2id_custom_276_-1" style="width: 195px;"&gt;&lt;a href="javascript:void(0)" class="select2-choice select2-default" tabindex="-1"&gt;   &lt;span class="select2-chosen" id="select2-chosen-6"&gt;- none -&lt;/span&gt;&lt;abbr class="select2-search-choice-close"&gt;&lt;/abbr&gt;   &lt;span class="select2-arrow" role="presentation"&gt;&lt;b role="presentation"&gt;&lt;/b&gt;&lt;/span&gt;&lt;/a&gt;&lt;label for="s2id_autogen6" class="select2-offscreen"&gt;Proc Fee&lt;/label&gt;&lt;input class="select2-focusser select2-offscreen" type="text" aria-haspopup="true" role="button" aria-labelledby="select2-chosen-6" id="s2id_autogen6"&gt;&lt;div class="select2-drop select2-display-none crm-container select2-with-searchbox"&gt;   &lt;div class="select2-search"&gt;       &lt;label for="s2id_autogen6_search" class="select2-offscreen"&gt;Proc Fee&lt;/label&gt;       &lt;input type="text" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" class="select2-input" role="combobox" aria-expanded="true" aria-autocomplete="list" aria-owns="select2-results-6" id="s2id_autogen6_search" placeholder=""&gt;   &lt;/div&gt;   &lt;ul class="select2-results" role="listbox" id="select2-results-6"&gt;   &lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;&lt;select class="crm-select2 crm-form-select" data-crm-custom="Commission:Proc_Fee" data-api-entity="Contribution" data-api-field="custom_276" data-option-edit-path="civicrm/admin/options/proc_fee_20191113181638" name="custom_276_-1" id="custom_276_-1" tabindex="-1" title="Proc Fee" style="display: none;"&gt;
      &lt;option value=""&gt;- none -&lt;/option&gt;
      &lt;option value="accordpt30"&gt;Accord - PT - 0.30%&lt;/option&gt;
      &lt;option value="accordresidirect045"&gt;Accord - Resi - Direct - 0.45%&lt;/option&gt;
  &lt;/select&gt; &lt;a href="/civicrm/admin/options/proc_fee_20191113181638?reset=1" class="crm-option-edit-link medium-popup crm-hover-button" target="_blank" title="Edit Options" data-option-edit-path="civicrm/admin/options/proc_fee_20191113181638"&gt;&lt;i class="crm-i fa-wrench"&gt;&lt;/i&gt;&lt;/a&gt;&amp;nbsp;
            &lt;/td&gt;
    &lt;/tr&gt;
  </code></pre>
  
Tags: <custom-fields><ajax>
Title: Using fieldOptions with Custom Fields
ThreadText: # Using fieldOptions with Custom Fields
  
  (Asked by: username_0 on 2019-11-27)
  
  I have a "Select list" within a Contribution Form. I want to populate the "Select List" with Custom Field values.
  
  I have created the Custom Group under Contacts, so i want to search all contacts and get the custom field "Title" from that Custom group.
  
  Then depending on the "Option" selected i want field values to populate.
  
  I have tried to use the:
  
  hook\_civicrm\_fieldOptions but its not working (<https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_fieldOptions/>).
  
  Any advise on how to do this?
  
  Thanks
  
  This is the HTML for field i want to populate:
  
  ```
  <tr class="custom_field-row custom_276_-1-row">
      <td class="label"><label for="custom_276_-1">Proc Fee</label>
        <a class="helpicon" title="Proc Fee Help" aria-label="Proc Fee Help" href="#" onclick="CRM.help(&quot;Proc Fee&quot;, {&quot;id&quot;:276,&quot;file&quot;:&quot;CRM\/Custom\/Form\/CustomField&quot;}); return false;">&nbsp;</a>    </td>
      <td class="html-adjust">
        <div class="select2-container crm-select2 crm-form-select" id="s2id_custom_276_-1" style="width: 195px;"><a href="javascript:void(0)" class="select2-choice select2-default" tabindex="-1">   <span class="select2-chosen" id="select2-chosen-6">- none -</span><abbr class="select2-search-choice-close"></abbr>   <span class="select2-arrow" role="presentation"><b role="presentation"></b></span></a><label for="s2id_autogen6" class="select2-offscreen">Proc Fee</label><input class="select2-focusser select2-offscreen" type="text" aria-haspopup="true" role="button" aria-labelledby="select2-chosen-6" id="s2id_autogen6"><div class="select2-drop select2-display-none crm-container select2-with-searchbox">   <div class="select2-search">       <label for="s2id_autogen6_search" class="select2-offscreen">Proc Fee</label>       <input type="text" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" class="select2-input" role="combobox" aria-expanded="true" aria-autocomplete="list" aria-owns="select2-results-6" id="s2id_autogen6_search" placeholder="">   </div>   <ul class="select2-results" role="listbox" id="select2-results-6">   </ul></div></div><select class="crm-select2 crm-form-select" data-crm-custom="Commission:Proc_Fee" data-api-entity="Contribution" data-api-field="custom_276" data-option-edit-path="civicrm/admin/options/proc_fee_20191113181638" name="custom_276_-1" id="custom_276_-1" tabindex="-1" title="Proc Fee" style="display: none;">
      <option value="">- none -</option>
      <option value="accordpt30">Accord - PT - 0.30%</option>
      <option value="accordresidirect045">Accord - Resi - Direct - 0.45%</option>
  </select> <a href="/civicrm/admin/options/proc_fee_20191113181638?reset=1" class="crm-option-edit-link medium-popup crm-hover-button" target="_blank" title="Edit Options" data-option-edit-path="civicrm/admin/options/proc_fee_20191113181638"><i class="crm-i fa-wrench"></i></a>&nbsp;
            </td>
    </tr>
  
  ```
  
  **Tags:** custom-fields, ajax
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-11-27. Score: 2 | Accepted answer
  
  As I haven't seen your code, I can only suggest what worked for me:
  
  ```
  function myext_civicrm_fieldOptions($entity, $field, &$options, $params) {
  
    if ($entity == 'Contribution') {
      if (isset($field) && $field == 'mycustomfield_123') {
        $myArray = [
          1 => 'Title 1',
          2 => 'Title 2'
        ];
        $options = $myArray;
      }
    }
  }
  
  ```
  
  > **Comments:**
  > **username_0**: Hi mate, thanks this has worked if i associate it with a field on the contrubution form but when i try to link to a custom field for e.g. custom_276_-1. Nothing happens  
  > **username_1**: @username_0 try to set $field == 'custom_276'  
  > **username_0**: That worked! Thank you very much! I need more things to get to my end goal but this really helped.  
  
  ---
  
  