5

I've searched here and on the CiviCRM forum but haven't been able to find an answer to what I was hoping would be fairly simple.

I want to give people the option of making their contribution recurring, however I don't want the checkbox checked when the form loads I only want the checkbox checked if the user selects it. This is to avoid an embarrassing situation a month down the road when we process their donation again.

Here's a page with the form in test mode

I'm not all that good with code, but did look with Developer Tools and found this:

<!-- .tpl file invoked: CRM/Contribute/Form/Contribution/Main.tpl. Call via form.tpl if we have a form in the page. -->

I looked at Main.tpl (lines 147-177) but don't understand enough to remove the checked="checked" attribute from the input tag.

{if $form.is_recur}
<div class="crm-section {$form.is_recur.name}-section">
<div class="label">&nbsp;</div>
<div class="content">
  {$form.is_recur.html} {$form.is_recur.label} {ts}every{/ts}
{if $is_recur_interval}
    {$form.frequency_interval.html}
  {/if}
  {if $one_frequency_unit}
    {$frequency_unit}
    {else}
    {$form.frequency_unit.html}
  {/if}
  {if $is_recur_installments}
    <span id="recur_installments_num">
    {ts}for{/ts} {$form.installments.html} {$form.installments.label}
    </span>
  {/if}
  <div id="recurHelp" class="description">
    {ts}Your recurring contribution will be processed automatically.{/ts}
    {if $is_recur_installments}
      {ts}You can specify the number of installments, or you can leave the number of installments blank if you want to make an open-ended commitment. In either case, you can choose to cancel at any time.{/ts}
    {/if}
    {if $is_email_receipt}
      {ts}You will receive an email receipt for each recurring contribution.{/ts}
    {/if}
  </div>
</div>
<div class="clear"></div>

{/if}

Thanks in advance.

4

You're in the right place to see what's going on, but the wrong spot to do anything. The field will arrive in the template fully-rendered, within {$form.is_recur.html} or an equivalent Smarty variable. Editing the template won't help you there.

The form PHP code would allow you to change it, but that's not the best way to go about this: doctoring core CiviCRM code is a bad idea, and while there's a way to set up override files for code files, it's a clunky method. Besides, you'd have to navigate Quickform, which is a headache in itself.

The better approach to forcing a checkbox checked or not is to use jQuery. You'll have CSS-style selectors, so you won't need to troll through the templates to see where to alter the box. You can add your code in one of three places:

  1. Somewhere in your WordPress theme
  2. In an extension you write, using the Resource addScriptFile method to add a script within hook_civicrm_buildform (the preferred method)
  3. Using an .extra.tpl file in your template override directory
  • 1
    3 would be my recommendation, then 2, then 1. If you already have an extension built for other purposes, then you could consider implementing a hook on buildForm to set the default. See wiki.civicrm.org/confluence/display/CRMDOC/… – Joe Murray May 28 '15 at 2:18
  • Thanks Andrew. I was pretty sure that {$form.is_recur.html} was the variable I wanted to look at, I just didn't know where it was defined. I definitely don't want to mess with core files, so I'll try the jQuery route. Thanks. – jursulak May 28 '15 at 5:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.