I need to perform a simple update of default values to a few CiviContribution forms on a client site. I was reminded that developing a Drupal module to customize the behavior of CiviCRM was the way to accomplish what we are in need of accomplishing. I coded up the following module:
<?php
/**
* buildForm hook
*/
function civicrm_cir_civicrm_buildForm( $formName, &$form )
{
// Only operate on CiviCRM Contribution Forms
if ( $formName == 'CRM_Contribute_Form_Contribution_Main' )
{
// Test for specific contribution forms by CiviCRM form ID
if ($form->getVar( '_id' ) == 15 || // Yearly CC
$form->getVar( '_id' ) == 16 || // Yearly PP
$form->getVar( '_id' ) == 13 || // Monthly CC
$form->getVar( '_id' ) == 14 || // Monthly PP
$form->getVar( '_id' ) == 8 ) // Weekly CC
{
// Set the check box for recurring contribution
$defaults['auto_renew'] = array('checked' => '1');
$form->setDefaults( $defaults );
}
}
}
Initially when the CiviContribution forms are loading, the Drupal module fires in the desired form data change... The recurring contribution check box is checked.
However when the form finishes loading the check box flips back to unchecked, and the default selection price becomes bolded simultaneously.
A Drupal developer I know who is not vary familiar with the code of CiviCRM suggested perhaps if CiviCRM uses the Drupal Form API to build its forms, then I could use the "Hook Alter" type API's to rearrange the order these events fire in... allow the CiviCRM form default population to occur first, and then fire my custom module (above) to check the AutoRenew check box.
Or if this is still not the correct way to check the AutoRenew check box in current CiviCRM powered by Drupal 6.x, then please kindly advise what is the correct way to check the AutoRenew check box.
I am thankful,
Michael