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) »
  • Setting defaults for Contribution Tracker hook?
Pages: [1]

Author Topic: Setting defaults for Contribution Tracker hook?  (Read 1362 times)

jbertolacci

  • I post occasionally
  • **
  • Posts: 54
  • Karma: 1
Setting defaults for Contribution Tracker hook?
January 07, 2010, 04:06:54 pm
I have drupal module with hook_civicrm_buildForm implementing Contribution Tracker fields as described here:

http://wiki.civicrm.org/confluence/display/CRMDOC/Update+custom+fields+in+contributions+and+events+by+passing+variables+in+a+URL

Works great.

Now I am trying to test if the fields are passed in the GET request and set defaults if they are not. I thought just updating $_GET might work but no luck:
Code: [Select]
function imba_civicrm_buildForm( $formName, &$form ) {
    // enable congtribution tracker feature
    if ( ( $formName == 'CRM_Contribute_Form_Contribution_Main' ||
           $formName == 'CRM_Contribute_Form_Contribution_Confirm' ||
           $formName == 'CRM_Contribute_Form_Contribution_ThankYou' ) &&
           $form->getVar( '_id' ) == 12 ) { // use  CONTRIBUTION PAGE ID here

        // Is custom field in the GET request? If not set it.
if (!isset($_GET['custom_19']) || is_null($_GET['custom_19'])) {
$_GET['custom_19'] = 'IMBA US';
}

        // use the custom field ID and custom field label here
        $trackingFields = array( 'custom_19' => 'List',
                                 'custom_20' => 'Campaign Code',
                                 'custom_21' => 'Package',
                                 'custom_76' => 'Region',
                                 'custom_77' => 'Chapter',
                                 );
        $form->assign( 'trackingFields', $trackingFields );      
    }
} // function imba_civicrm_buildForm

Wondered if I might see the tracking fields in the  form object, but not seeing there either.
 
Code: [Select]
but CRM_Core_Error::debug( $form );
I am probably missing something obvious, but could use some help with a pointer in the right direction.

Thanks,

jason
« Last Edit: January 09, 2010, 03:06:42 pm by jbertolacci »

jbertolacci

  • I post occasionally
  • **
  • Posts: 54
  • Karma: 1
Re: Setting defaults for Contribution Tracker hook?
January 09, 2010, 03:33:12 pm
Thanks lobo for the reply to this on IRC. The solution for setting $_GET values in the hook is this code:

Quote
if (!$_GET['custom_4']) {
         $_GET['custom_4'] = "Summer2009";
          require_once 'CRM/Core/BAO/CustomGroup.php';
          $getDefaults = CRM_Core_BAO_CustomGroup::extractGetParams( $this, "'Contact', 'Individual', 'Contribution'" );
          if ( ! empty( $getDefaults ) ) {
                    $form->setDefaults( $getDefaults );
          }
}

I also added this to the online documentation:

http://wiki.civicrm.org/confluence/display/CRMUPCOMING/Update+custom+fields+in+contributions+and+events+by+passing+variables+in+a+URL
« Last Edit: January 09, 2010, 03:47:04 pm by jbertolacci »

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Setting defaults for Contribution Tracker hook?

This forum was archived on 2017-11-26.