CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Example customization to set prefix based on gender
Pages: [1]

Author Topic: Example customization to set prefix based on gender  (Read 773 times)

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Example customization to set prefix based on gender
August 29, 2012, 12:01:22 am
One of our customers wants a customization:
  • they only want to use the prefixes Mr. and Mrs. (in Dutch though)
  • they want to set this prefix automatically based on the gender

This is what we have done to get this:
  • modify the template CRM/Contact/Form/Edit/Individual.tpl to make the prefix readonly
  • use the hook pre to set the prefix with this bit of code:
Code: [Select]
   
function eecustom_civicrm_pre( $op, $objectName, $objectId, &$objectRef ) {
   
    if ( $objectName == "Individual" ) {
if ( $op == "create" || $op == "edit" ) {
switch ( $objectRef['gender_id'] ) {
case 1:
$objectRef['prefix_id'] = 1;
break;
case 2:
$objectRef['prefix_id'] = 2;
break;
default:
$objectRef['prefix_id'] = 0;
break;
}
}
}
}


« Last Edit: August 29, 2012, 12:05:22 am by Erik Hommel »
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Example customization to set prefix based on gender
August 29, 2012, 03:30:58 am
Nice
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Example customization to set prefix based on gender
August 29, 2012, 03:44:27 am
I had the request the other way around (set the gender based on the salutation).

Will try to wrap it in civix love as an extension end of the week
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Example customization to set prefix based on gender
August 29, 2012, 03:46:24 am
If only you'd just settle on 'hey you' life would be so much easier
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Example customization to set prefix based on gender
August 29, 2012, 05:41:53 am
I think we should build that in as a CiviCRM default! Hey you is certainly good enough for us :-)
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Example customization to set prefix based on gender

This forum was archived on 2017-11-26.