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 Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Make "I want to contribute this amount every month: box auto-checked
Pages: [1]

Author Topic: Make "I want to contribute this amount every month: box auto-checked  (Read 776 times)

jkirsner

  • I post occasionally
  • **
  • Posts: 40
  • Karma: 1
  • CiviCRM version: 4.1.2
  • CMS version: Drupal
  • MySQL version: unsure
  • PHP version: unsure
Make "I want to contribute this amount every month: box auto-checked
April 10, 2014, 06:10:40 am
Hello,

My organization has a separate monthly giving page and want to have the box auto-checked to make it a re-curring contribution so people don't do what they have been doing (intending to make a monthly gift, forgetting to check the box, and not responding when we try and fix the problem). Is there a way to make this either default to checked on this page, or to default it to checked and hide the box?

Thanks!

-Jessica

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: Make "I want to contribute this amount every month: box auto-checked
April 10, 2014, 08:02:06 am
Greetings Jessica,

Last I dealt with this same request, the suggestion at that time was to create a custom Drupal module to inject/force the box to check when the particular contribution page loads. Following is sample code I was working with back then...

Code: [Select]
<?php

/**
 * buildForm hook
 */
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);
        //});
    
}

}

We are not using it, though... I believe we changed the way we were setting up the contribution pages and thus avoided needing this hack.

P.S. You can find out the MySQL and PHP versions from your Drupal Admin Status page.

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

JonGold

  • Ask me questions
  • ****
  • Posts: 638
  • Karma: 81
    • Palante Technology
  • CiviCRM version: 4.1 to the latest
  • CMS version: Drupal 6-7, Wordpress 4.0+
  • PHP version: PHP 5.3-5.5
Re: Make "I want to contribute this amount every month: box auto-checked
April 10, 2014, 08:13:01 am
Hi Jessica,

There's no way to do it using the CiviCRM GUI, but it's a pretty good introduction to using a template "extra" file.  Documentation for the general technique is here: http://book.civicrm.org/developer/current/techniques/templates/.  I'll include step-by-step instructions for your scenario though:

* Check Administer menu -> System Settings -> Directories, ensure there's a custom templates folder selected.
* Within your custom templates folder, create the following folder structure: CRM/Contribute/Form/Contribution
* In the Contribution folder, create a file called "Main.extra.tpl".
* The contents of that file should be:

Code: [Select]
{literal}
<script type="text/javascript">
cj(document).ready(function () {
  cj('#is_recur').prop('checked',true);
  cj('.is_recur-section').hide();
});
</script>
{/literal}

* If you want to check the box but not hide it (good for testing!) remove the third line starting with "cj".
* This will apply to ALL donation pages.  Since it sounds like you only want to apply it to one page, find the id of that contribution page (it's in the URL for that page as "id=xxx"), and create a folder within the Contribution folder, e.g. CRM/Contribute/Form/Contribution/4.  Move the Main.extra.tpl file to the "4" folder.

I just saw mdleuck's post - that's also a legit way to handle this!  We both use jQuery, we just apply it to the page differently.  Using a hook is slightly more complicated but also more sophisticated.  Note that his code shouldn't be copied verbatim to a Civi 4.4 installation, since the jQuery is old and the reference to the checkbox is no longer correct in his code.
Sign up to StackExchange and get free expert CiviCRM advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

jkirsner

  • I post occasionally
  • **
  • Posts: 40
  • Karma: 1
  • CiviCRM version: 4.1.2
  • CMS version: Drupal
  • MySQL version: unsure
  • PHP version: unsure
Re: Make "I want to contribute this amount every month: box auto-checked
April 10, 2014, 08:33:46 am
Thanks so much for all the suggestions!  :)

secularaugust

  • I’m new here
  • *
  • Posts: 26
  • Karma: -1
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 7.22
  • MySQL version: 5.1.41-3ubuntu12.10
  • PHP version: 5.3
Re: Make "I want to contribute this amount every month: box auto-checked
April 10, 2014, 12:53:14 pm
JonGold,

Thanks so much for the code and guide!

I'm trying to help Jessica with this.  I tried to follow your directions by creating 

.../htdocs/sites/default/files/civicrm/templates/CRM/Form/Contribute/Form/Contribution/5/Main.extra.tpl  (/templates is set as the templates director on the Directories page)

The contents of which are

Code: [Select]
{literal}
<script type="text/javascript">
cj(document).ready(function () {
  cj('#is_recur').prop('checked',true);
});
</script>
{/literal}

It seems like https://vashti.secularstudents.org/civicrm/contribute/transact?reset=1&id=5 should be loading with the "I want to contribute this amount every month" check, but it's not.

Any idea what I'm doing wrong?

Thanks!

JonGold

  • Ask me questions
  • ****
  • Posts: 638
  • Karma: 81
    • Palante Technology
  • CiviCRM version: 4.1 to the latest
  • CMS version: Drupal 6-7, Wordpress 4.0+
  • PHP version: PHP 5.3-5.5
Re: Make "I want to contribute this amount every month: box auto-checked
April 10, 2014, 01:41:20 pm
Hi August,

That all looks good to me - but I can imagine that maybe because you're on version 4.3 it might be a little different?

Your problem is most likely one of the following:
* That Javascript isn't getting loaded.
* It's getting loaded, but isn't doing what we expect.

Those two problems have very different solutions, so first let's test.  The quickest way to test is to add an alert.  See my updated code, and note the "window.alert" line I added below.  If, upon loading the page, you see a pop-up that says "test!", your Javascript is loading.  Post back here, and we can troubleshoot.  If the pop-up doesn't happen, then check for typos in the folder names.

Also, while viewing the donation page, select "View Source" (Ctrl+U in Firefox).  Search the page for:  .tpl
Ensure that the path and filename of the .tpl file matches what I told you - it might be different in version 4.3.  Also - you may want to try loading it against all contribution pages until we know it's working, then limit it to page 5.


Code: [Select]
{literal}
<script type="text/javascript">
cj(document).ready(function () {
  cj('#is_recur').prop('checked',true);
});
window.alert('test!');
</script>
{/literal}
Sign up to StackExchange and get free expert CiviCRM advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

secularaugust

  • I’m new here
  • *
  • Posts: 26
  • Karma: -1
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 7.22
  • MySQL version: 5.1.41-3ubuntu12.10
  • PHP version: 5.3
Re: Make "I want to contribute this amount every month: box auto-checked
April 17, 2014, 11:42:57 am
Jon,

Thanks so much!

It was the path being different.  I was able to find the correct path via hunting through the source for .tpl just like you suggested.

All the best!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Make "I want to contribute this amount every month: box auto-checked

This forum was archived on 2017-11-26.