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) »
  • Passing variables to Contribute page in the url
Pages: [1]

Author Topic: Passing variables to Contribute page in the url  (Read 1352 times)

nicol

  • I post occasionally
  • **
  • Posts: 95
  • Karma: 5
  • CiviCRM version: 4.2, 4.3, 4.4
  • CMS version: Joomla 2.5.x, Joomla 3.x Wordpress 3.x, Drupal 7.x
  • MySQL version: 5.x
  • PHP version: 5.3 / 5.4
Passing variables to Contribute page in the url
November 21, 2013, 11:03:35 am
I'm wanting to add a donations slider so people can chose the price they want to donate more visually (a bit Humble Bundle inspired). My thinking is to do this with javascript on a separate page, and then once they've chosen a price forward them to a contribution page which pre-populates a donation field. In an ideal world (!) it would select the appropriate membership for their donation level, and add the remainder as an extra donation on top, tho I realise that's probably pushing my luck - passing a donation value into a donation field on a contribution page alone would be great.

I saw something linked to this here - http://wiki.civicrm.org/confluence/display/CRMDOC33/Update+custom+fields+in+contributions+and+events+by+passing+variables+in+a+URL - for Drupal, wondering if that's CMS agnostic and something similar could work in Joomle with a different URL structure.

many thanks
Nic

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Passing variables to Contribute page in the url
November 21, 2013, 11:49:32 am
IMO you should implement the JS slider directly on the contribution page. It should be very simple to do:

1) Create a contribution page that accepts "Other amount" only (no price set, no price options)
2) Include your javascript. There are a number of ways to do this, but I would do it by implementing hook_buildForm, checking if you are on the right form and then calling CRM_Core_Resources::singleton()->addScriptFile()
3) Tell your js to hide the "other amount" input and replace it with a slider :)
Try asking your question on the new CiviCRM help site.

nicol

  • I post occasionally
  • **
  • Posts: 95
  • Karma: 5
  • CiviCRM version: 4.2, 4.3, 4.4
  • CMS version: Joomla 2.5.x, Joomla 3.x Wordpress 3.x, Drupal 7.x
  • MySQL version: 5.x
  • PHP version: 5.3 / 5.4
Re: Passing variables to Contribute page in the url
November 21, 2013, 12:10:06 pm
Very interesting, thanks..

From a UX perspective - I'd prefer to have a page inviting the donation with nothing for the user to do but drag the slider and hit 'donate' - and I can also stick that on every page of the site. If it's on the contribution page then all the boxes to fill in could be more daunting.

(I might also be biased as my JS skills are pretty beginner - but if there's no way to pass the amount in the URL I might just have to do it.)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Passing variables to Contribute page in the url
November 21, 2013, 01:05:25 pm
You can use the buildForm hook to get the param from the url and populate the amount field too.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Passing variables to Contribute page in the url
November 21, 2013, 01:12:00 pm
I was about to say that, thanks X.
So instead I'll say this - why don't we include a slider option in core? I think it'd be popular, and would be another one of those "eye candy" things like the dashboard that makes Civi look good.
Try asking your question on the new CiviCRM help site.

nicol

  • I post occasionally
  • **
  • Posts: 95
  • Karma: 5
  • CiviCRM version: 4.2, 4.3, 4.4
  • CMS version: Joomla 2.5.x, Joomla 3.x Wordpress 3.x, Drupal 7.x
  • MySQL version: 5.x
  • PHP version: 5.3 / 5.4
Re: Passing variables to Contribute page in the url
November 21, 2013, 01:31:20 pm
ok, thanks alot.

So I'd create a Joomla plugin something like this - http://wiki.civicrm.org/confluence/display/CRMDOC42/Example+Joomla+Plugin+for+implementing+hooks - and add buildForm hook something like this - http://wiki.civicrm.org/confluence/display/CRMDOC40/CiviCRM+hook+specification#CiviCRMhookspecification-hook_civicrm_buildForm ?

A slider in core would be very cool. If I manage to do anything nice with it I'll put it on github!

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: Passing variables to Contribute page in the url
November 21, 2013, 01:51:24 pm

+1 for slider in core and/or an extension

Also populating the default amount should be a core feature. Its a bit too common that folks should not have to implement a hook for it, IMO

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

nicol

  • I post occasionally
  • **
  • Posts: 95
  • Karma: 5
  • CiviCRM version: 4.2, 4.3, 4.4
  • CMS version: Joomla 2.5.x, Joomla 3.x Wordpress 3.x, Drupal 7.x
  • MySQL version: 5.x
  • PHP version: 5.3 / 5.4
Re: Passing variables to Contribute page in the url
November 24, 2013, 08:31:57 pm
Populating the default amount through URL in the core would be so good.

(I also wouldn't be in the current mess!)

Based on two pages in the Wiki (how to make a Joomla plugin, and how to do url passes in a Drupal module), I've made a plugin with the following code:

Code: [Select]
<?php

// No direct access
defined('_JEXEC') or die;
 
jimport('joomla.plugin.plugin');
class 
plg_civicrm_contribute extends JPlugin
{

function 
civitracker_civicrm_buildForm( $formName, &$form ) {
    
// enable tracking feature
    
if ( ( $formName == 'CRM_Contribute_Form_Contribution_Main' ||
           
$formName == 'CRM_Contribute_Form_Contribution_Confirm' ||
           
$formName == 'CRM_Contribute_Form_Contribution_ThankYou' ) &&
           
$form->getVar( '_id' ) == 6 ) 
           
           { 
// use  CONTRIBUTION PAGE ID here
   $trackingFields = array( 'price_13' => 'Contribution Amount',
    'email-5' => 'Email Address' );
           
$form->assign( 'trackingFields', $trackingFields );
   }
}
}
?>


It installs ok,  but when I feed in a url like below, nothing gets populated:
Code: [Select]
index.php?option=com_civicrm&view=Contributions&Itemid=424&price_13=20&email-5=address@email.com

Seems like lots of things I could have got wrong here, not sure if it's an easy bug fix,
nic

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: Passing variables to Contribute page in the url
November 25, 2013, 06:56:25 am

Seems like you just cut-n-pasted the code from an example

Not sure how your plugin will fill in the default values in the form? can u explain?

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

nicol

  • I post occasionally
  • **
  • Posts: 95
  • Karma: 5
  • CiviCRM version: 4.2, 4.3, 4.4
  • CMS version: Joomla 2.5.x, Joomla 3.x Wordpress 3.x, Drupal 7.x
  • MySQL version: 5.x
  • PHP version: 5.3 / 5.4
Re: Passing variables to Contribute page in the url
November 25, 2013, 07:33:41 am
Hello,

I'm sorry - I should have stated more clearly that I don't really have a clue what I'm doing here.

I was inspired by the 'very simple' line and the fact that there are two sample plugins - one for passing a value to a contribuition page http://wiki.civicrm.org/confluence/display/CRMDOC33/Update+custom+fields+in+contributions+and+events+by+passing+variables+in+a+URL and one for using hooks in a Joomla plugin http://wiki.civicrm.org/confluence/display/CRMDOC42/Example+Joomla+Plugin+for+implementing+hooks and thought I could merge the two. I kind of assumed that 'form->assign' was a function for passing values.

I think I got over-ambitious about what I could do after managing to get the slider to work as desired http://fundyourfilm.com/index2.html - sorry for wasting people's time!

thanks
nic

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviContribute (Moderator: Donald Lobo) »
  • Passing variables to Contribute page in the url

This forum was archived on 2017-11-26.