I know I can do it using civicrm_buildForm but I don't know:

  • How to get the custom field
  • How to set the value to this field
  • What is your civicrm version? Commented Mar 21 at 17:44
  • @PradeepNayak 5.65.1 Commented Mar 21 at 17:45
  • Are you talking about offline contribution form? Commented Mar 21 at 17:51

1 Answer 1


You can do something like below you can use API4 to get the exact machine names


function extname_civicrm_buildForm($formName, &$form) {
  if ($formName == 'CRM_Contribute_Form_Contribution_Main') {
    if (isset($_GET['custom_59'])) {
      $customFieldId = \Civi\Api4\CustomField::get(FALSE)
        ->addWhere('name', '=', 'is_eligible')
        ->addWhere('custom_group_id:name', '=', 'gift_aid')
        ->first()['id'] ?? NULL;
      if (!empty($customFieldId)) {
          'custom_' . $customFieldId => $_GET['custom_59'],
  • Thanks @PradeepNayak. However 59 is the custom field ID, right? My local env database is different from the prod database, so I need to get this custom field without using its ID. It's possible? Commented Mar 21 at 17:55
  • If you are using the same machine name then yes possible. Commented Mar 21 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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