// Get the ID of a custom field named "email" $emailKey = "email"; $fieldID = CRM_Core_BAO_CustomField::getKeyID($emailKey); echo "The ID of the $emailKey field is $fieldID";
// Get the ID of a custom field based on a user-selected key name $userSelectedKey = $_POST['custom_field_key']; $fieldID = CRM_Core_BAO_CustomField::getKeyID($userSelectedKey); echo "The ID of the $userSelectedKey field is $fieldID";In this example, we retrieve the key name of a custom field that was selected by a user and submitted through a form using the POST method. We pass this key name to the getKeyID function and store the returned ID in the $fieldID variable. We then output a message that displays the name of the field and its corresponding ID. Package Library: The package library for this function is the "civicrm-core" library, which is a part of the CiviCRM framework.