1

I have a Custom Group with two custom fields: Field A is a view only input field (ID: custom_32) Field B is a select with a few options (ID: custom_33).

When the user selects one option from Field B and hits save I would like to add a value to Field A based on the selected option.

Which hook shall I use for this?

I tried civicrm_preProcess, civicrm_postProcess and civicrm_validateForm.

My aproach to the problem is to alter the submitted (empty) value in the form object but it doesn't seem to work.

function insert_value_for_b($formName, &$form){
    //determine $newValue
    //other business logic
    $data = &$form->controller->container();
    $data['values']['CustomData'][$customIDforB] = $newValue;
}

Could someone advise please?

2

View only fields can only be updated via the API, see: https://issues.civicrm.org/jira/browse/CRM-17843

So you could use one of the hooks (eg: hook_civicrm_pre) to 'detect' when that field has changed, and read the value, and then use the API to set the other value. _pre might be more reliable than the form hooks, as the field might be set by other methods than by submitting a form.

For example:

function foo_civicrm_pre($op, $objectName, $id, &$params) {
  if ($objectName == 'Contact' && empty($params['custom_xxx'])) {
    // make an API call to set custom_yyy
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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