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) »
  • How to access contact from hook_civicrm_postProcess($formName, &$form) ?
Pages: [1]

Author Topic: How to access contact from hook_civicrm_postProcess($formName, &$form) ?  (Read 331 times)

artfulrobot.com

  • I post occasionally
  • **
  • Posts: 81
  • Karma: 4
How to access contact from hook_civicrm_postProcess($formName, &$form) ?
December 01, 2014, 05:05:15 am
I have a contribution form that exposes a custom field using a profile. I now need to add some business logic when this is saved, specifically: updating another field in the same custom fieldset.

I thought I'd use the postProcess hook, to react only on
Code: [Select]
CRM_Contribute_Form_Contribution_Main  but this does not seem to have any of the info/objects created in the processing. e.g. I want to know which contact has just been edited (by id), so I can edit it further.

Or I could use a generic object pre/post hook, which would give me some object Ids, but lose the context (the fact that it's this particular hook operating). In other contexts I do not want this particular code to run.

Hmmm. Ideas? Thanks in advance!

artfulrobot.com

  • I post occasionally
  • **
  • Posts: 81
  • Karma: 4
Re: How to access contact from hook_civicrm_postProcess($formName, &$form) ?
December 01, 2014, 07:53:05 am
I've found a work-around, which is to add the other field that needs updating into the profile and use an .extra.tpl on CRM/Contribute/Form/Contribution/Main.extra.tpl  to add the required value to this field, then hide it. This is possible because in this case the logic is v. simple. But it's a bodge and would not be suitable if the value was not supposed to allow the possibility of the user tinkering with it! ... So still interested in better ways.

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: How to access contact from hook_civicrm_postProcess($formName, &$form) ?
December 02, 2014, 11:32:24 pm
I think the JS approach is probably going to be a bit easier to maintain -- but agree that it can't handle sensitive fields.

Did you try using the civicrm_developer module to inspect the hook data? In similar situations, I've found it helpful to get a visual display of the information being generated by the hooks.

http://wiki.civicrm.org/confluence/display/CRMDOC/Hook+Reference#HookReference-Inspectinghooks

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • How to access contact from hook_civicrm_postProcess($formName, &$form) ?

This forum was archived on 2017-11-26.