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) »
  • Customizing the CiviContribute form through Drupal module
Pages: [1]

Author Topic: Customizing the CiviContribute form through Drupal module  (Read 1138 times)

mdlueck

  • Ask me questions
  • ****
  • Posts: 382
  • Karma: 4
  • CiviCRM version: 4.7.24
  • CMS version: Drupal 6.x
  • MySQL version: 5.5.54
  • PHP version: 5.3.10
Customizing the CiviContribute form through Drupal module
June 14, 2015, 01:58:54 pm
Greetings,

I am coming back to this older Q&A forum as my thread on Stack Exchange is getting no further feedback. Perhaps Stack Exchange is not meant for CiviCRM extending / development type questions?

Anyway, I needed 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:

Code: [Select]
<?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 Lueck
Lueck Data Systems
http://www.lueckdatasystems.com/

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Customizing the CiviContribute form through Drupal module
June 14, 2015, 03:56:11 pm
StackExchange is meant to be quite simple. Post a question, get answers. It doesn't work though when you keep posting more questions on the same thread, because it's not a discussion forum, and you posted them as if they were answers. People answer questions, not answers. If you have a new question, you should post a new question.

Your question above would be good to post on StackExchange, as it's not what you posted before (at least not what you posted as a question).
Try asking your question on the new CiviCRM help site.

mdlueck

  • Ask me questions
  • ****
  • Posts: 382
  • Karma: 4
  • CiviCRM version: 4.7.24
  • CMS version: Drupal 6.x
  • MySQL version: 5.5.54
  • PHP version: 5.3.10
Re: Customizing the CiviContribute form through Drupal module
June 16, 2015, 03:02:42 am
Greetings Coleman,

(sheesh...) Confusing that the protocol of StackExchange is to separate / break up an issue / final solution... "micromanagers" = YUCK!  ???

I will copy from above, post a new question at StackExchange as I perceive I will not get the solution in this forum system any longer.

I am thankful,
--
Michael Lueck
Lueck Data Systems
http://www.lueckdatasystems.com/

Chris Burgess

  • Ask me questions
  • ****
  • Posts: 675
  • Karma: 59
Re: Customizing the CiviContribute form through Drupal module
June 18, 2015, 03:34:16 pm
I don't think there is an attempt to micromanage here, Martin. StackExchange has a format, and sticking to the format is what's rapidly made it a really valuable resource. The question and answer elements are clearly labelled and while it's less of a "loose" environment than the forum, it's become a comparably powerful resource in a few months for the same reason.

Perhaps there's a loose analogy to be made with structure in DB storage: by using a structure, we're able to build better things than if there's no structure.

I recommend taking a few minutes to familiarise yourself with the new environment, I'm sure it will pay off (if it hasn't already with the **excellent** answers you've already obtained ;)).

There is a tour at http://civicrm.stackexchange.com/tour and there is inline help when posting a question: http://civicrm.stackexchange.com/questions/ask

The discussion fields are clearly labelled "Question", "Answer" and "Comment", and each serves a distinct purpose - with some  blurring at times of course, because human discourse is a fluid exchange!

The forum is likely to remain open for more general discussion, and I'm sure others have had both positive and negative reactions to the change, but I think the SE site has already proved its value. By understanding how to use it well, you should also find the SE site a very useful part of the CiviCRM community and your own toolkit.

EDIT: This question (on CiviCRM meta.SE) may be helpful? http://meta.civicrm.stackexchange.com/questions/4/civicrm-stackexchange-vs-civicrm-forum?rq=1
« Last Edit: June 18, 2015, 03:37:18 pm by Chris Burgess »
@xurizaemon ā— www.fuzion.co.nz

Chris Burgess

  • Ask me questions
  • ****
  • Posts: 675
  • Karma: 59
Re: Customizing the CiviContribute form through Drupal module
June 18, 2015, 04:21:22 pm
Answer @ http://civicrm.stackexchange.com/questions/3263/customizing-the-civicontribute-form-through-drupal-module/3265#3265 updated, and apologies for misreading your name Michael :)
@xurizaemon ā— www.fuzion.co.nz

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Customizing the CiviContribute form through Drupal module

This forum was archived on 2017-11-26.