3

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

What I'm trying to achieve is changing the values of each option programmatically when the form gets built. According to the hook reference, 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 and cannot find the appropriate functions.

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.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.