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 (Moderator: Donald Lobo) »
  • detecting custom field values upon submission of new/edited Participation
Pages: [1]

Author Topic: detecting custom field values upon submission of new/edited Participation  (Read 698 times)

TwoMice

  • I post frequently
  • ***
  • Posts: 214
  • Karma: 16
    • Emphanos
  • CiviCRM version: Always current stable version
  • CMS version: Drupal 7
detecting custom field values upon submission of new/edited Participation
May 18, 2010, 05:37:43 pm
I'm working to trigger some specific business logic based on the value of a custom Participation field.  Specifically, I want to save contacts into a particular group based on their answer to a question at registration.  This needs to work for online registrations and for manually created event participations.

I've tried doing this using hook_civicrm_post(), using some code like the this:

if ($objectName == 'Participant' && $op == 'create') {
    switch ($_REQUEST['custom_24']) {
        case 1:
            // do something
        break;

        case 2:
            // do something
        break;
           
        case 3:
            // do something
        break;
    }
}


Questions:
  • Unfortunately, the name of the field is not always the same.  When an anonymous user creates an online registration, the field value is in $_REQUEST['custom_24'], but when an authenticated user creates a manual participation record, the field value is in $_REQUEST['custom_24-1'].  Not knowing all the possible ways this value could come in through $_REQUEST, I hesitate to rely on this method.

  • Is accessing $_REQUEST directly the only (or best) way to get the value of the custom field that's been submitted?  By the time we get to civicrm_post, the value will have been saved, but I see it's not part of $objectRef.

I suspect the answer is somewhere under CRM/Custom, but I'm hoping to avoid a few hours of trial and error.

Thanks,
Allen

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

TwoMice

  • I post frequently
  • ***
  • Posts: 214
  • Karma: 16
    • Emphanos
  • CiviCRM version: Always current stable version
  • CMS version: Drupal 7
Re: detecting custom field values upon submission of new/edited Participation
May 19, 2010, 07:04:04 am
Follow-up:

Got lobo on IRC and he suggested a couple of things:

1. Loop through $_REQUEST and split each key on '-' until first element matches 'custom_24'

2. Use CRM_Core_BAO_CustomValueTable::getValues() to get the value from DB

He suggested looping through $_REQUEST might be faster than getting it from the DB, but not sure.
Please consider contributing to help improve CiviCRM with the Make it Happen! initiative.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • detecting custom field values upon submission of new/edited Participation

This forum was archived on 2017-11-26.