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) »
  • Support »
  • Using CiviCRM »
  • Using CiviMember (Moderator: Deepak Srivastava) »
  • How to customize a few things on Contribution Forms
Pages: [1] 2

Author Topic: How to customize a few things on Contribution Forms  (Read 3145 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
How to customize a few things on Contribution Forms
December 22, 2010, 02:14:31 pm
Greetings:

Civi 3.3.1 on current Drupal

We would like to customize a few things on contribution pages:

1) To be able to bold and or italic some text within the "Contribution Label" text. Is there some Civi BB code language that such fields accept / interpret? When trying HTML tags, they get translated into literal string values which get displayed at run-time.

2) We would like to set the "recurring contribution" radio button as the default button.

Suggestions as to how to accomplish these tweaks? Thank you!!!
--
Michael Lueck
Lueck Data Systems
http://www.lueckdatasystems.com/

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: How to customize a few things on Contribution Forms
December 22, 2010, 05:34:47 pm

for 2, you can use the hook_civicrm_buildForm and set the default to be recurring

i'm not sure you can do 1 easily. One potential option is to customize the template and replace the contribution label directly in the template

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

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: How to customize a few things on Contribution Forms
December 23, 2010, 01:01:40 pm
Thank you Lobo.

I am looking over the sample Drupal code as well as the docs here:
http://wiki.civicrm.org/confluence/display/CRMDOC33/CiviCRM+hook+specification#CiviCRMhookspecification-hookcivicrmbuildForm

Where would I look up the correct string/name of the form from our site for this value? Ex:
$formName == 'CRM_Contribute_Form_Contribution_Main'

And where would I find out the field name associated with the radio button "I want to contribute this amount every..."?

<><><>

On a coding style topic... would it be correct for this hook_civicrm_buildForm API to test for "condition A" leaving the possability to add "condition B", "condition C", etc... in the future? I do not think the sample civitest.module.sample would actually run with multiple "function civitest_civicrm_buildForm()" lines in it. So I am thinking ahead to prepare for the next time we need to hook this hook_civicrm_buildForm API. Would that be the correct way to code while keeping "next time" in mind?
--
Michael Lueck
Lueck Data Systems
http://www.lueckdatasystems.com/

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: How to customize a few things on Contribution Forms
December 23, 2010, 01:40:42 pm
Getting closer...

Seems I happened on the correct form name for the form in what I copy / pasted.

As to the field, seems I want to set/select the CIVICRM_QFID_1_16 radio button.

And from one example, I gather that my impression of how to code this hook was indeed correct... so all set for next time.

Off to take our children sledding, then back for more Civi fun!  ;D
« Last Edit: December 23, 2010, 01:45:07 pm by mdlueck »
--
Michael Lueck
Lueck Data Systems
http://www.lueckdatasystems.com/

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: How to customize a few things on Contribution Forms
December 23, 2010, 06:06:20 pm

You might also want to read:

http://en.flossmanuals.net/CiviCRM/DevelopIntro

This information should be there (if not, we should add it!)

yeah, civitest.module.sample will not compile :) A better example that uses a fair number of hooks is:

http://svn.civicrm.org/sfschool/branches/v3.2/drupal/sfschool/sfschool.module

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

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: How to customize a few things on Contribution Forms
December 24, 2010, 06:29:45 am
Thank you for the pointers, Lobo.

I read through the developer section... mainly focused on this page: http://en.flossmanuals.net/CiviCRM/DevelopHooks

I see pre-populating text fields, not radio buttons.

Could I have a specific radio button hint? And yes I will contribute a working example back to the docs.
--
Michael Lueck
Lueck Data Systems
http://www.lueckdatasystems.com/

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: How to customize a few things on Contribution Forms
December 24, 2010, 07:09:30 am

try using

Code: [Select]
  $defaults['RADIO_BUTTON_ELEMENT_NAME'] = 1;
  $form->setDefaults( $defaults );

So in this case:

http://drupal.demo.civicrm.org/civicrm/event/register?reset=1&id=1

should be: $defaults['CIVICRM_QFID_561_6'] = 1

main issue is radio button ids are non deterministic (i think). could not find an easy workaroud for this

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

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: How to customize a few things on Contribution Forms
December 24, 2010, 08:21:53 am
hhhmmm... sensing I may soon need to set up a full test environment and install the suggested debugger.

The radio button you stated at the test site (the $200 button) does not come up pre-selected. The reoccurring button is not selected on our site.

I simplified the code in the test below, eliminating the check if it is one of the correct form ID's. Additionally I set the system default button to 0 to see if by chance they were both trying to be selected.

Code: [Select]
function civicrm_cir_civicrm_buildForm( $formName, &$form ) {

    // Pre-set the forms to recurring
    if ( $formName == 'CRM_Contribute_Form_Contribution_Main' ) {
        // Set the radio button for recurring contribution
        $defaults['CIVICRM_QFID_0_14'] = 0;
        $defaults['CIVICRM_QFID_1_16'] = 1;
        $form->setDefaults( $defaults );
    }

}

Does your comment about "non deterministic" mean that you suspect the radio button list really can not be pre-selected, or did you mean only that the name of the field might chance, so beware?
--
Michael Lueck
Lueck Data Systems
http://www.lueckdatasystems.com/

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: How to customize a few things on Contribution Forms
December 29, 2010, 04:29:26 am
Lobo, could you possibly clarify what you meant here?

Quote from: mdlueck on December 24, 2010, 08:21:53 am
Does your comment about "non deterministic" mean that you suspect the radio button list really can not be pre-selected, or did you mean only that the name of the field might chance, so beware?

Time to dig in again after Christmas!  ;)

I do not wish to set up a full dev environment / install the suggested PHP debugger if in your opinion setting the correct default radio button is probably impossible. Thank you!
--
Michael Lueck
Lueck Data Systems
http://www.lueckdatasystems.com/

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: How to customize a few things on Contribution Forms
December 29, 2010, 06:57:30 am
There is another approach--with 3 lines of jQuery, you can also pre-select a radio button. I have used such a solution to very similar problems.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

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: How to customize a few things on Contribution Forms
December 29, 2010, 07:07:23 am
@hershel: Oh cool! Please explain further!!!  :o

Perhaps a code snippet. I have never coded using jquery, just have heard of its existence.
--
Michael Lueck
Lueck Data Systems
http://www.lueckdatasystems.com/

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: How to customize a few things on Contribution Forms
December 29, 2010, 07:40:57 am
On http://drupal.demo.civicrm.org/civicrm/event/register?reset=1&id=1 (this minute at least) "$ 100,00 Couple" is pre-selected. Presuming the IDs are the same each time this page loads, then code something like this:

Code: [Select]
$(function() {
  $('#CIVICRM_QFID_562_2').attr('checked', true);
});

would select "$ 50,00 Single".
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

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: How to customize a few things on Contribution Forms
December 29, 2010, 08:50:23 am
hhhmmm... I tried to modify my module thusly:

Code: [Select]
function civicrm_cir_civicrm_buildForm( $formName, &$form ) {

    // Pre-set the forms to recurring
    if ( $formName == 'CRM_Contribute_Form_Contribution_Main' ) {
        // Set the radio button for recurring contribution
        $(function() {
          $('#CIVICRM_QFID_1_16').attr('checked', true);
        });
    }

}

Which results in:

Parse error: syntax error, unexpected '(', expecting T_VARIABLE or '$' in /srv/www/sites/domain.org/www/sites/all/modules/civicrm_cir/civicrm_cir.module on line 11

So off in search of how to code jQuery in PHP within a Drupal mod.

Note: LOC 11 is the "$(function() {" line.
« Last Edit: December 29, 2010, 08:53:07 am by mdlueck »
--
Michael Lueck
Lueck Data Systems
http://www.lueckdatasystems.com/

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: How to customize a few things on Contribution Forms
December 29, 2010, 09:02:33 am
Emm, you are trying to put JS code into a PHP file. That inherently won't work.

The code I posted must go into either a JS file or into an inline <script> tag.

jQuery is Javascript, not PHP. It's executed client side by the browser, as opposed to server side by the server.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

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: How to customize a few things on Contribution Forms
December 29, 2010, 09:32:55 am
All right, then if I toss it in say the Drupal theme JS file, then how would I only have if affect (currently) these four pages?

Code: [Select]
   // Pre-set the forms to recurring
    if ( ( $formName == 'CRM_Contribute_Form_Contribution_Main' ) && (
         $form->getVar( '_id' ) == 1 ||     // Yearly PP
         $form->getVar( '_id' ) == 8 ||     // Monthly CC
         $form->getVar( '_id' ) == 9 ||     // Monthly PP
         $form->getVar( '_id' ) == 10 ) ) { // Yearly CC

I would think that having that code in the theme JS file... would try to execute on EVERY page for the entire site, no?
--
Michael Lueck
Lueck Data Systems
http://www.lueckdatasystems.com/

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviMember (Moderator: Deepak Srivastava) »
  • How to customize a few things on Contribution Forms

This forum was archived on 2017-11-26.