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 CiviContribute (Moderator: Donald Lobo) »
  • Providing default values in recurring payment form
Pages: [1]

Author Topic: Providing default values in recurring payment form  (Read 3738 times)

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Providing default values in recurring payment form
November 17, 2007, 02:49:20 pm
I have a contribution page that is configured to use PayPal Standard, which is configured to allow recurring payments.  I would like to default the text input field to "1" for the frequency of the payments. I would also like to default the number of installments to "12".    The reason for this is the vast majority of the people filling out this form want to pay once a month for 12 months.

Which file should I edit to accomplish this?

Thanks,
Sarah
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

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: Providing default values in recurring payment form
November 17, 2007, 10:47:04 pm

CRM/Contribute/Form/Contribution/Main.php

line 126 or so. (in function setDefaultValues)

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

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Providing default values in recurring payment form
November 18, 2007, 04:19:49 pm
Thanks! I got it working the way I want.
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

civicpixel

  • I’m new here
  • *
  • Posts: 25
  • Karma: 3
Re: Providing default values in recurring payment form
July 23, 2008, 05:19:12 pm
I'm trying to do this exact same thing, but haven't been able to figure it out yet.

I've been trying to set the default via:
$this->_defaults['frequency_unit'] = 'month';

That seems to have zero effect. Can someone who's figured this out point me in the right direction?
(CiviCRM 2.0.4)

Thanks!
Brian

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: Providing default values in recurring payment form
July 23, 2008, 07:43:25 pm

i was doing some contribution stuff so checked this out, and it worked for me. Here are the 2 lines i added

Code: [Select]
        $this->_defaults['frequency_unit'] = 'monthly';
        $this->_defaults['frequency_interval'] = 3;

1. ensure that it is at the top level of the function (i.e. not surronded by any conditional)
2. clear your session (sesssionReset=2) after you make the code fixes, this helps clear up any old state etc

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

civicpixel

  • I’m new here
  • *
  • Posts: 25
  • Karma: 3
Re: Providing default values in recurring payment form
July 25, 2008, 09:09:45 am
Thanks Lobo, I should have cleared the session!

In case anyone else is looking to do this:
Code: [Select]
$this->_defaults['frequency_unit'] = 'monthly';has to be:
Code: [Select]
$this->_defaults['frequency_unit'] = 'month';
On the version of CiviCRM I'm running (2.0.4). I assume it's changed since then if monthly worked for Lobo. In 2.0.4 a good place to add those lines is after line 135 in CRM/Contribute/Form/Contribution/Main.php

Thanks again,
Brian

orthodoxkohen

  • I post occasionally
  • **
  • Posts: 59
  • Karma: 2
Re: Providing default values in recurring payment form
July 04, 2009, 08:36:08 pm
Where would this be in version 2.2.0?  I cant figure out where I would put the defaults in.  Here's what I have in function setDefaultValues:
Code: [Select]
function setDefaultValues( )
    {
        // process defaults only once
        if ( ! empty( $this->_defaults ) ) {
            // return $this->_defaults;
        }

I would like to default at monthly intervals and unlimited months.
Thanks,

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: Providing default values in recurring payment form
July 05, 2009, 08:57:35 am

your best bet would be to set the defaults of those form values by implementing the  buildForm hook

for an example check here:

http://forum.civicrm.org/index.php?topic=7227.0

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

galgeek

  • I’m new here
  • *
  • Posts: 24
  • Karma: 1
  • CiviCRM version: 4.6.0
  • CMS version: drupal 7.36
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Providing default values in recurring payment form
September 10, 2013, 02:20:15 pm
Should something as simple as this work?

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

    if ( $formName == 'CRM_Contribute_Form_Contribution_Main' ) {
        $defaults['frequency_unit'] = 'month';
        $defaults['frequency_interval'] = '1';
        $form->setDefaults( $defaults );
    }
}

I'm not seeing any value set in the frequency interval box on my form.

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: Providing default values in recurring payment form
September 10, 2013, 02:54:00 pm

are you seeing the unit being set properly.

browser behavior is a bit strange sometimes for select/radio boxes. can you logout and log back in (which resets the session) and try again

thanx

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

galgeek

  • I’m new here
  • *
  • Posts: 24
  • Karma: 1
  • CiviCRM version: 4.6.0
  • CMS version: drupal 7.36
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Providing default values in recurring payment form
September 10, 2013, 04:11:01 pm
Logging out and back in doesn't appear to change anything.  I've tried other browsers, too.

I've done a drush cc all since I created and installed the module.

If I leave the interval field blank, I get the error message "Please correct the following errors in the form fields below:
Please enter a number for how often you want to make this recurring contribution (EXAMPLE: Every 3 months)." ... so it looks like the value's not getting set behind the scenes.

There's nothing related in drupal's log.

Yashodha Chaku

  • Forum Godess / God
  • Ask me questions
  • *****
  • Posts: 755
  • Karma: 57
    • CiviCRM
Re: Providing default values in recurring payment form
September 11, 2013, 06:08:09 am
Code: [Select]
function mymodule_civicrm_buildform( $formName, &$form ) {

    if ( $formName == 'CRM_Contribute_Form_Contribution_Main' ) {
        $defaults['frequency_unit'] = 'month';
        $defaults['frequency_interval'] = '3';
        $form->setDefaults( $defaults );
    }
}

The above piece of code seems to be doing right thing for me i,e I want to contribute this amount every 3 months

Can you try to clear all caches, templates_c etc

HTH
-Yashodha
Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

galgeek

  • I’m new here
  • *
  • Posts: 24
  • Karma: 1
  • CiviCRM version: 4.6.0
  • CMS version: drupal 7.36
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Providing default values in recurring payment form
September 11, 2013, 05:56:09 pm
Just to be clear, I began with only the unit, not the interval, enabled on the page itself.

I've made sure to do /civicrm/clearcache and drush cc all, and clear my browsers' caches, and still neither of my defaults show up.  :'(

It's not a big problem for the moment to leave the form as a simple monthly recurring, but it seems like my first little hook isn't loading, though its module is enabled, and I'd sure like to know what I've flubbed.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviContribute (Moderator: Donald Lobo) »
  • Providing default values in recurring payment form

This forum was archived on 2017-11-26.