Answers.Body: <p>If the options that are shown on the profile are custom fields, then the radio options displayed might be the option values of some option groups.</p>
  
  <p>To add/remove any options from the profile, you can make use of <a href="https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_fieldOptions" rel="nofollow noreferrer"><code>fieldOpions</code></a> hook. Eg -</p>
  
  <pre><code>function hook_civicrm_fieldOptions($entity, $field, &amp;$options, $params) {
    //replace 1 with your custom address field id
    if ($field == 'custom_1') { 
      $options['my_option'] = 'My Custom Option';
    }
  }
  </code></pre>
  
  <p>Check the doc for more info about the param, etc.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-28T11:01:21.997Z
Answers.LastActivityDate: 2018-08-28T11:01:21.997Z
Answers.UserDisplayName: jitendra - fuzion
Body: <p>I have a CiviCRM profile that hosts a custom field. The custom field is of type "Radio-Button" and hosts two options:</p>
  
  <p><a href="https://i.sstatic.net/xMZBC.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/xMZBC.png" alt="enter image description here"></a></p>
  
  <p>What I'm trying to achieve is changing the values of each option programmatically when the form gets built. According to the <a href="https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_buildForm/" rel="nofollow noreferrer">hook reference</a>, the <code>buildForm</code> hook should be used for doing such changes. </p>
  
  <p>I know it's possible to change default values for simple input fields, it can be done by calling the <code>$form-&gt;setDefaults( $defaults )</code> function. But how does one modify more complicated HTML form elements such as radio buttons? </p>
  
  <p>I browsed the <code>CRM_Core_Form</code> <a href="https://doc.symbiotic.coop/dev/civicrm/v47/phpdoc/CRM_Core_Form.html" rel="nofollow noreferrer">PHP class reference</a> and cannot find the appropriate functions.</p>
  
Tags: <custom-fields><profile><php><forms>
Title: How to change the value of a custom radio button field programmatically?
ThreadText: # How to change the value of a custom radio button field programmatically?
  
  (Asked by: username_0 on 2018-08-27)
  
  I have a CiviCRM profile that hosts a custom field. The custom field is of type "Radio-Button" and hosts two options:
  
  [![enter image description here](https://i.sstatic.net/xMZBC.png)](https://i.sstatic.net/xMZBC.png)
  
  What I'm trying to achieve is changing the values of each option programmatically when the form gets built. According to the [hook reference](https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_buildForm/), the `buildForm` hook should be used for doing such changes.
  
  I know it's possible to change default values for simple input fields, it can be done by calling the `$form->setDefaults( $defaults )` function. But how does one modify more complicated HTML form elements such as radio buttons?
  
  I browsed the `CRM_Core_Form` [PHP class reference](https://doc.symbiotic.coop/dev/civicrm/v47/phpdoc/CRM_Core_Form.html) and cannot find the appropriate functions.
  
  **Tags:** custom-fields, profile, php, forms
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-08-28. Score: 1
  
  If the options that are shown on the profile are custom fields, then the radio options displayed might be the option values of some option groups.
  To add/remove any options from the profile, you can make use of fieldOpions hook. Eg -
  function hook_civicrm_fieldOptions($entity, $field, &$options, $params) {
    //replace 1 with your custom address field id
    if ($field == 'custom_1') { 
      $options['my_option'] = 'My Custom Option';
    }
  }
  
  Check the doc for more info about the param, etc.
  
  
  ---
  
  