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) »
  • Adding fields to Contact Summary
Pages: [1]

Author Topic: Adding fields to Contact Summary  (Read 1175 times)

muenzer

  • I’m new here
  • *
  • Posts: 13
  • Karma: 1
Adding fields to Contact Summary
August 01, 2010, 10:46:15 am
I'm trying to add a Spouse field to the Contact Summary page that acts similar to the Employee field.  I would like it pull the relationship on for the summary and then have the auto complete on the edit page.  From going through the documentation there seems to be multiple ways of going about this.  It looks like I could use the api in templates, add code in the custom php directory, use hooks, etc. 

Is there a recommended way to do this type of customization?  Ideally something that is the least likely to break on a version update.  Thanks for your help.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Adding fields to Contact Summary
August 01, 2010, 11:19:17 am

if you can do this all in the templates via template customization and usign crmAPI i would use that approach. that seems to be the least invasive (IMO)

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

muenzer

  • I’m new here
  • *
  • Posts: 13
  • Karma: 1
Re: Adding fields to Contact Summary
August 01, 2010, 11:31:00 am
Thanks for your feedback.  The only thing I'm not too sure about with using templates and crmAPI is how to update the information after an edit.  Are you aware of any examples of this being done in templates?

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Adding fields to Contact Summary
August 01, 2010, 05:29:26 pm

no, have not done a lot of modifications via templates

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

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: Adding fields to Contact Summary
August 02, 2010, 12:43:46 am
You would probably need to use a hook (postProcess or pre) to update after the edit.
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

muenzer

  • I’m new here
  • *
  • Posts: 13
  • Karma: 1
Re: Adding fields to Contact Summary
August 07, 2010, 11:09:41 am
If anyone is interested, I used this code in hook_civicrm_buildForm to add the fields:
Code: [Select]
$form->addElement( 'text', 'spouse', ts( 'Spouse' ) );
$form->addElement( 'hidden', 'spouse_id', NULL, array('id'=>'spouse_id'));
$defaults = array( 'spouse' => $spouse, 'spouse_id' => $spouse_id );
$form->setDefaults( $defaults );

And this code in hook_civicrm_postProcess to get the submitted values:
Code: [Select]
$values = $form->getVar( '_submitValues' );
$spouse_id = $values['spouse_id'];

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Adding fields to Contact Summary

This forum was archived on 2017-11-26.