Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- civicrm_api3('contact', 'create', ['id'=>123, 'gender'=>'Male'])
- function getIdforLabel($entity, $field, $label) {
- $result = civicrm_api3($entity, 'getoptions', ['sequential' => 1, 'field' => $field]);
- if ($result['is_error']) {
- throw new Exception("Failed to getoptions for $entity.$field");
- }
- foreach ($result['values'] as $result) {
- if ($result['value'] == $label) {
- return $result['key'];
- }
- }
- throw new Exception("Supplied value, '$label' is not a valid option.");
- }
- $gender_id = getIdForLabel('contact', 'gender_id', 'Male');
- civicrm_api3('contact', 'create', ['id'=>$contact_id, 'gender_id'=>$gender_id]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement