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) »
  • Requiring users to check recurring contributions check box
Pages: [1]

Author Topic: Requiring users to check recurring contributions check box  (Read 446 times)

RedJohn

  • I’m new here
  • *
  • Posts: 1
  • Karma: 0
  • CiviCRM version: 4.4.0
  • CMS version: Joomla! 2.5.11
  • MySQL version: 5.5.37-cll
  • PHP version: 5.3.27
Requiring users to check recurring contributions check box
August 04, 2014, 09:02:41 am
The site I am working on has two separate donations pages. One dedicated to one time donations and one dedicated to recurring donations. Right now CIVIContribute lets the users choose whether to check the recurring donation box or not on the monthly donations page. This has lead to a lot of confusions both with the users not making the donations they wanted to and with our system where we recently discovered sometimes it is being counted as a monthly contribution with our payment processor but is not being recorded monthly in CIVICRM (our research has lead us to suspect the two issues are related). What we would like to do is make the recurring donation check box required for the user to submit the transaction. If they do not wish to check the box they can then go or be directed to our one time contribution page. Does anyone have any ideas on how this could be accomplished?

Thanks for everyone's time on the matter!

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Requiring users to check recurring contributions check box
August 04, 2014, 11:12:04 am
You could do a form preProcess hook that sets a default for that field and then freezes it, based on form id.
Try asking your question on the new CiviCRM help site.

flug

  • I post frequently
  • ***
  • Posts: 126
  • Karma: 12
Re: Requiring users to check recurring contributions check box
August 29, 2014, 07:00:17 am
Another option would be to edit/create a custom version of the contribution page template (saving it in your custom_templates directory) and use the contribution page id to customize the recurring option radio buttons to be what you'd like

FYI here is a link telling where the code for the recurring part of the form is and how to modify it (for a different purpose than what you are doing, but similar enough to give you some hints):

 http://wiki.civicrm.org/confluence/display/CRMDOC/Modifications+to+Contribution+Page+Templates

And here is some template code we used to modify event confirmation emails based on event id.  Your mod to the contribution page template would look sort of similar except, obviously, based on contribution page id.  I confess don't know what the variable name is for contribution page id (or even for certain if it is available to the template without some custom coding).

Code: [Select]
      {if $event.id  eq '7461'}
             <p>{$event.confirm_email_text|html2text}</p>
      {else}
             <p>{$event.confirm_email_text}</p>
     {/if}

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Requiring users to check recurring contributions check box
August 29, 2014, 07:17:35 am
I think a php hook will turn out to be more maintainable than a tpl override.
Tpl overrides, as a rule, should be a last resort because it requires you to maintain a complete copy of a template file and hand-merge in changes with each upgrade (or not merge them and watch your site break).
Try asking your question on the new CiviCRM help site.

flug

  • I post frequently
  • ***
  • Posts: 126
  • Karma: 12
Re: Requiring users to check recurring contributions check box
August 29, 2014, 08:34:08 am
Yes, looking at the tpl more carefully it would have been a mess to try to do that particular mod at that level.

What seems to work is this hook:

Code: [Select]
function hook_civicrm_buildForm($formName, &$form) {
 //echo $form->_id . ' hi ';
if ($formName == "CRM_Contribute_Form_Contribution_Main" && $form->_id == 35) {
 
    $form->setDefaults(array('is_recur' => 1));
    unset($form->_elements[$form->_elementIndex['is_recur']]->_elements[0]);
  }
}

Obviously, change 'hook' in the function name to match the name of your module.

The $form->_id is the id of your contribution page.  You can see the ID number in the URL if you edit that contribution page etc.

This is based on the comment here:   http://forum.civicrm.org/index.php?topic=17372.15  It has the disadvantages noted in that comment, but it does work and doesn't look terrible.  Presumably you could set the form element to hidden if you want it to look better.  (Though if you do that, you would probably also want to mod the TPL, or removing/modifying the explanatory text that the TPL inserts after the recurring contribution form element somehow, because that text won't make any sense once the recurring options are gone).

Edit: Note that the $formName == part is very necessary and also, must come before the $form->_id == part.  (Often the $form->_id is protected value and so you get a nasty error trying to access it).
« Last Edit: August 29, 2014, 09:05:15 am by flug »

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Requiring users to check recurring contributions check box
August 31, 2014, 03:54:55 pm
I agree being able to set a page to only allow recurring contributions is a fairly frequent request. I'm not sure the right answer to solving though. I did go down the path of setting up an extension which held various extra Contribution & Event page customisations (custom thank you page, create relationship of type x if cid=0 is used) - the main problem is injecting these options in a satisfactory way into the back-end contribution pages (I don't see custom tpls as satisfactory as that's not upgradeable and the fields seem to pop up in odd places when adding by hook).

Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviContribute (Moderator: Donald Lobo) »
  • Requiring users to check recurring contributions check box

This forum was archived on 2017-11-26.