Aller directement à la fin des métadonnées
Aller au début des métadonnées

Documentation Search

CiviCRM 4.3 Documentation

Developer Resources

CiviCRM books!

Make sure to check out our Online User/Administrator and Developer Guides! You can also support this project by ordering a hard copy.

Or support us by buying an eBook or hard copy of Using CiviCRM from Packt Publishing.

If you are using hook_install() or something similar to customize CiviCRM programmatically, you might want to create custom field groups and custom fields programmatically too. If your installer assumes it starts with an uncustomized CiviCRM installation, your installer can create custom groups and fields without fear that they might already exist by using the Custom Data Group and Custom Field APIs.

What if you are not working with a clean install, or for some other reason just need to see whether the custom groups and fields already exist? You can query the database directly, or you can use the sample code below.

Let's say you think you might have a custom field group with the internal name of 'My_custom_fields'. Here's a sample call to check:

To check for the existence of a custom field with the label 'My field' within that group (assuming it was found):

Note that custom field group names have underscores (added by CiviCRM when you create a group through the Admin UI), while custom field labels are the actual names you provided to CiviCRM in the UI, most likely without underscores.