Aller directement à la fin des métadonnées
Aller au début des métadonnées

We are currently working on a way to make the Thank You page options in CiviCRM a bit more flexible to allow people to drive donors to a page other than a CiviCRM Thank You page after a contribution is made. Often times organizations want to drive someone to a tell a friend page, or a custom page with content after someone has contributed. This creates a way for organizations to maximize the time that they have their constituents attention to ask them to take an additional action in support of the campaign.

Here is the workflow we imaged:

1) CiviCRM admin creates contribution page

2) At Thank You and Receipt settings page, CiviCRM admin is presented with two radio buttons:

  1. "Redirect user to a specific URL"
    1. This option is selected by default and displays an open text field to enter the URL
  2. "Display a Custom Thank-You Page"
    1. This will reveal the standard CiviCRM Thank You page options

3) CiviCRM admin saves settings and sets contribution page to go live

4) User comes to page to make a contribution, enters information on form, and clicks to submit

5) User confirms contribution

6) After confirmation, user will be directed to URL entered on "Thank You and Receipt" page

So the challenges we have faced:

1) CiviCRM requires a title for thank you pages. We had to make this field unrequired in order to get this to work. This is not the optimal solution as this allows someone to potentially change their mind after enter a redirect field to just having a thank you page and not put in a title.

2) CiviCRM seems to be forcing the donor to a thank you page after contribution versus the URL that was entered for redirect.

Here is the code we used:

  1. <?php
  2. // $Id$
  3. /**
  4.  * @file
  5.  * Adds custom CiviCRM functionality.  This changes the Thank You settings form
  6.  * for Contribution pages and adds an input for a redirect URL and stores in in the DB.
  7.  * Then when a user goes through the contribution page and confirm their donation, they
  8.  * are redirected to that URL instead of seeing the Thank You page.
  9.  /{*}
  10. /**
  11.  * Implementation of civicrm hook_buildForm().
  12.  * @see http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+hook+specification
  13.  /{*}
  14. function jgi_civicrm_civicrm_buildForm($formName, &$form) {
  15.   // Contriubtion Page Thank you settings
  16.   if ($formName == 'CRM_Contribute_Form_ContributionPage_ThankYou') {
  17.     // Remove title requirement
  18.     $form->_required = array();
  19.     // Define options
  20.     $opts = array(
  21.       'url' => ts('Redirect user to a specific URL'),
  22.       'page' => ts('Display a Custom Thank-You Page')
  23.     );
  24.     // Add form elements
  25.     // Couldn't for the life of me figure out how to do this with $form->add
  26.     $form->addRadio('thankyou_method', null, $opts, array('onclick' =>"showMethod()", 'class' => 'radio_thankyou_method'), '<br />');
  27.     $form->add('text', 'thankyou_url', ts('URL to redirect to after contribution'));
  28.     // Get custom thankyou
  29.     $thankyou = db_fetch_object(db_query(

    "SELECT * FROM

    Unknown macro: {civicrm_thankyou_custom}

    WHERE contrib_page_id = %d"

    , $_GET['id']));
  30.     if ($thankyou) {
  31.       // Set URL
  32.       $form->getElement('thankyou_url')->setValue($thankyou->thankyou_url);
  33.       // Set method radio (not working)
  34.       $radio = $form->getElement('thankyou_method');
  35.       $form->getElement('thankyou_method')->setValue($thankyou->thankyou_method ? 'url' : 'page');
  36.     {color:#66cc66}}
    #   }
  37. }
  38. /**
  39.  * Implementation of civicrm hook_postProcess().
  40.  * @see http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+hook+specification
  41.  /{*}
  42. function civicrm_civicrm_postProcess($formName, &$form) {
  43.   // This is the part that is attempting to redirect.  We basically just need the Contribution Page ID
  44.   // and then we can look it up in the DB and do a redirect.  The problem I am running into is that
  45.   // the formName does not seem to be unique and things are redirected when they shouldn't be
  46. /*
  47.   // Contribution page confirmation form
  48.   if ($formName = 'CRM_Contribute_Form_Contribution_Confirm') {
  49.     $values = $form->_values;
  50.     $redirect = $values['thankyou_url'];
  51.     $id = $form->get('id');
  52.    
  53.     if ($id && $redirect) {
  54.       $redirect = check_plain($redirect);
  55.       drupal_goto($redirect);
  56.     }
  57.   }
  58. */
  59.   // Contribution Thankyou configuration form
  60.   if ($formName == 'CRM_Contribute_Form_ContributionPage_ThankYou') {
  61.     $vals = $form->getSubmitValues();
  62.     // $id = $_GET['id'];
  63.     $id = $form->get('id');
  64.     // Check if ID (cannot use drupal_write_record since the ID is not a serial type)
  65.     if ($id) {
  66.       $query = "
  67.      UPDATE

    Unknown macro: {civicrm_thankyou_custom}

    SET thankyou_method = %d, thankyou_url = '%s'

  68.      WHERE contrib_page_id = %d";
  69.       db_query($query, $vals['thankyou_method'], $vals['thankyou_url'], $id);
  70.     {color:#66cc66}}
    #     else {
  71.       $query = "
  72.      INSERT INTO

    Unknown macro: {civicrm_thankyou_custom}

    (contrib_page_id, thankyou_method, thankyou_url)

  73.      VALUES (%d, '%s', %d)";
  74.       db_query($query, $id, $vals['thankyou_method'], $vals['thankyou_url']);
  75.     {color:#66cc66}}
    #   }
  76. {color:#66cc66}}
    #  
    # /**
  77.  * Set custom values for the contribution page (called from Contribute_BAO)
  78.  */
  79. function civicrm_set_custom_values($id, &$values) {
  80.   $thankyou = db_fetch_object(db_query(

    {*}_"SELECT * FROM

    Unknown macro: {civicrm_thankyou_custom}

    WHERE contrib_page_id = %d"_{*}

    , $id));
  81.   if ($thankyou) {
  82.     $values['thankyou_method'] = $thankyou->thankyou_method ? 'url' : 'page';
  83.     $values['thankyou_url'] = $thankyou->thankyou_url;
  84.   {color:#66cc66}}
    # }
Étiquette
  • Aucun