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) »
  • Discussion (deprecated) »
  • Feature Requests and Suggestions »
  • Community Sponsored Improvements (Moderator: Donald Lobo) »
  • Changes to thank you page options
Pages: [1]

Author Topic: Changes to thank you page options  (Read 3633 times)

rczamor

  • I’m new here
  • *
  • Posts: 20
  • Karma: 2
Changes to thank you page options
May 17, 2009, 09:43:06 pm
We are working on a pretty awesome implementation of CiviCRM for a nonprofit organization that runs some pretty sophisticated online fundraising campaigns, and have tried to make a modification to the Thank You page to allow for either the creation of a standard CiviCRM thank you or redirect to a different page. For some reason the code we are using is not redirecting to the URL entered when we are doing testing.

I wanted to get some recommendations on ways we can implement this code. It seems like the system forces a person to a thank you page after confirmation of a contribution. Can you recommend where we look for the code that does this?

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Changes to thank you page options
May 18, 2009, 04:58:37 am
I think you need to be a little more specific about how you are trying to do this - are you just editing
civicrm\templates\CRM\Contribute\Form\Contribution\ThankYou.tpl or are you editing a php file or are you using a 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

rczamor

  • I’m new here
  • *
  • Posts: 20
  • Karma: 2
Re: Changes to thank you page options
May 19, 2009, 07:52:47 am
I created a page in the wiki here: http://wiki.civicrm.org/confluence/pages/createpage.action?spaceKey=CRMDOC&fromPageId=15402171

We are using a hook to implement this, which may be the issue. The code is here:



Quote
   1.
      <?php
   2.
      // $Id$
   3.
       
   4.
      /**
   5.
       * @file
   6.
       * Adds custom CiviCRM functionality to JGI.  This changes the Thank You settings form
   7.
       * for Contribution pages and adds an input for a redirect URL and stores in in the DB.
   8.
       * Then when a user goes through the contribution page and confirm their donation, they
   9.
       * are redirected to that URL instead of seeing the Thank You page.
  10.
       */
  11.
       
  12.
      /**
  13.
       * Implementation of civicrm hook_buildForm().
  14.
       * @see http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+hook+specification
  15.
       */
  16.
      function jgi_civicrm_civicrm_buildForm($formName, &$form) {
  17.
        // Contriubtion Page Thank you settings
  18.
        if ($formName == 'CRM_Contribute_Form_ContributionPage_ThankYou') {
  19.
          // Remove title requirement
  20.
          $form->_required = array();
  21.
          // Define options
  22.
          $opts = array(
  23.
            'url' => ts('Redirect user to a specific URL'),
  24.
            'page' => ts('Display a Custom Thank-You Page')
  25.
          );
  26.
          // Add form elements
  27.
          // Couldn't for the life of me figure out how to do this with $form->add
  28.
          $form->addRadio('thankyou_method', null, $opts, array('onclick' =>"showMethod()", 'class' => 'radio_thankyou_method'), '<br />');   
  29.
          $form->add('text', 'thankyou_url', ts('URL to redirect to after contribution'));
  30.
          // Get custom thankyou
  31.
          $thankyou = db_fetch_object(db_query("SELECT * FROM {jgi_civicrm_thankyou_custom} WHERE contrib_page_id = %d", $_GET['id']));
  32.
          if ($thankyou) {
  33.
            // Set URL
  34.
            $form->getElement('thankyou_url')->setValue($thankyou->thankyou_url);
  35.
            // Set method radio (not working)
  36.
            $radio = $form->getElement('thankyou_method');
  37.
            $form->getElement('thankyou_method')->setValue($thankyou->thankyou_method ? 'url' : 'page');
  38.
          }
  39.
        }
  40.
      }
  41.
       
  42.
      /**
  43.
       * Implementation of civicrm hook_postProcess().
  44.
       * @see http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+hook+specification
  45.
       */
  46.
      function jgi_civicrm_civicrm_postProcess($formName, &$form) {
  47.
       
  48.
        // This is the part that is attempting to redirect.  We basically just need the Contribution Page ID
  49.
        // and then we can look it up in the DB and do a redirect.  The problem I am running into is that
  50.
        // the formName does not seem to be unique and things are redirected when they shouldn't be
  51.
      /*
  52.
        // Contribution page confirmation form
  53.
        if ($formName = 'CRM_Contribute_Form_Contribution_Confirm') {
  54.
          $values = $form->_values;
  55.
          $redirect = $values['thankyou_url'];
  56.
          $id = $form->get('id');
  57.
         
  58.
          if ($id && $redirect) {
  59.
            $redirect = check_plain($redirect);
  60.
            drupal_goto($redirect);
  61.
          }
  62.
        }
  63.
      */
  64.
       
  65.
        // Contribution Thankyou configuration form
  66.
        if ($formName == 'CRM_Contribute_Form_ContributionPage_ThankYou') {
  67.
          $vals = $form->getSubmitValues();
  68.
          // $id = $_GET['id'];
  69.
          $id = $form->get('id');
  70.
          // Check if ID (cannot use drupal_write_record since the ID is not a serial type)
  71.
          if ($id) {
  72.
            $query = "
  73.
           UPDATE {jgi_civicrm_thankyou_custom} SET thankyou_method = %d, thankyou_url = '%s'
  74.
           WHERE contrib_page_id = %d";
  75.
            db_query($query, $vals['thankyou_method'], $vals['thankyou_url'], $id);
  76.
          }
  77.
          else {
  78.
            $query = "
  79.
           INSERT INTO {jgi_civicrm_thankyou_custom} (contrib_page_id, thankyou_method, thankyou_url)
  80.
           VALUES (%d, '%s', %d)";
  81.
            db_query($query, $id, $vals['thankyou_method'], $vals['thankyou_url']);
  82.
          }
  83.
        }
  84.
      }
  85.
       
  86.
      /**
  87.
       * Set custom values for the contribution page (called from Contribute_BAO)
  88.
       */
  89.
      function jgi_civicrm_set_custom_values($id, &$values) {
  90.
        $thankyou = db_fetch_object(db_query("SELECT * FROM {jgi_civicrm_thankyou_custom} WHERE contrib_page_id = %d", $id));
  91.
        if ($thankyou) {
  92.
          $values['thankyou_method'] = $thankyou->thankyou_method ? 'url' : 'page';
  93.
          $values['thankyou_url'] = $thankyou->thankyou_url;
  94.
        } 
  95.
      }


Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Discussion (deprecated) »
  • Feature Requests and Suggestions »
  • Community Sponsored Improvements (Moderator: Donald Lobo) »
  • Changes to thank you page options

This forum was archived on 2017-11-26.