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) »
  • using civicrm_post hook to retrieve custom values
Pages: [1]

Author Topic: using civicrm_post hook to retrieve custom values  (Read 1192 times)

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
using civicrm_post hook to retrieve custom values
September 04, 2010, 09:18:13 am
I'm trying to use civicrm_post hook to retrieve a custom value from a contribution form. the value is then mapped and saved in a different custom field.

the setValues is working fine. but i'm not able to retrieve the form value. I'm using:

Code: [Select]
$get_params = array('entityID' => $contribution_id,
        'custom_1' => 1 );
$values = CRM_Core_BAO_CustomValueTable::getValues($get_params);

where $contribution_id is the $objectId passed to the hook. I know that value is valid -- there is indeed a contribution id at that point in the process. But it seems the custom value is not yet saved, and thus not retrievable via that entity id at the point the post hook is called. the other values passed to the hook (like $objectRef) don't include the form values. what's the best way to retrieve that value?
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

TwoMice

  • I post frequently
  • ***
  • Posts: 214
  • Karma: 16
    • Emphanos
  • CiviCRM version: Always current stable version
  • CMS version: Drupal 7
Re: using civicrm_post hook to retrieve custom values
September 04, 2010, 09:58:32 am
What about just grabbing the value from $_POST, if it's set?  Something like this:

Code: [Select]
$customValue = CRM_Utils_Array::value('custom_1', $_POST, '0');  // setting 0 as default if 'custom_1' is not found
if ($customValue) {
    // save custom value
}

Seems rather clumsy, since we know the _post() hook is being fired at times when this form is not submitted.  But I think it would get the job done.  Otherwise I'm not aware of another way.

- TM
Please consider contributing to help improve CiviCRM with the Make it Happen! initiative.

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Re: using civicrm_post hook to retrieve custom values
September 04, 2010, 05:08:24 pm
I ended up just grabbing from $_REQUEST, and that worked fine.

but I'm running into another issue -- the value of the field doesn't load on edit
this is in a new contribution form (backend), so where I'm at is the field appears fine, I can select and save, value is stored, but when I edit and existing record, the value does not load -- and thus if I proceed to save, the value is lost.

it's definitely saving the value on the initial form load/save. I'm not seeing where I need to preload the value on edit.
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

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: using civicrm_post hook to retrieve custom values
September 04, 2010, 07:17:40 pm

use the buildForm hook and set the default values there

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

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Re: using civicrm_post hook to retrieve custom values
September 04, 2010, 07:34:56 pm
I did that and it worked. Retrieved using:
CRM_Core_BAO_CustomValueTable::getValues

but it just seems clumsy. i add the element to the form, then need to retrieve the value in case i'm editing an existing record and set it as the default. i guess I expected that quickform addElement would do the work of retrieving an existing value. oh well.
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

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: using civicrm_post hook to retrieve custom values
September 04, 2010, 09:39:52 pm

the addElement / add function has no idea of where the value ends up. So not sure how it can figure out where to get the value from when building the form element

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

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • using civicrm_post hook to retrieve custom values

This forum was archived on 2017-11-26.