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) »
  • Can I add a URL parameter to pre-fill in the donation amount.
Pages: [1]

Author Topic: Can I add a URL parameter to pre-fill in the donation amount.  (Read 715 times)

RachelWright

  • I post occasionally
  • **
  • Posts: 78
  • Karma: 3
  • CiviCRM version: 4.2.7
  • CMS version: Joomla 2.5.17
  • MySQL version: 5.5.37
  • PHP version: 5.4.26
Can I add a URL parameter to pre-fill in the donation amount.
November 25, 2014, 02:31:38 pm
Hi Guys -

I am trying to figure out a way to pass the contribution amount through a URL parameter. For instance,

base.org?option=com_civicrm&task=civicrm/contribute/transact&reset=1&id=1&donationamount=50

What I'm looking to be able to do is send this link out with various amounts depending on the donor. (Not that I can't send them an email that says please type in X amount, but it would greatly eliminate confusion if I could have the amount pre-filled in for them.)

I found this wiki article but couldn't quite figure out how to tailor it to my needs:
http://wiki.civicrm.org/confluence/display/CRMDOC/Update+custom+fields+in+contributions+and+events+by+passing+variables+in+a+URL

Thoughts?

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Can I add a URL parameter to pre-fill in the donation amount.
December 01, 2014, 10:10:21 am
Hey there,

I had a QUICK look at https://github.com/civicrm/civicrm-core/blob/master/CRM/Contribute/Form/Contribution/Main.php and couldn't see how you would do it.. I do remember people talking about it a while ago though (about 7 years ago, or so!) and they gave me the impression that it was possible so I'll ask them to pipe up here in case I am not imagining it.

If it isn't possible, I think it would make a great contribution, if you were able to make it happen. Let me know.

Michael
Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Can I add a URL parameter to pre-fill in the donation amount.
December 01, 2014, 12:19:21 pm
I think we had it working - but not through old methods as far as I recall
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

Chris Burgess

  • Ask me questions
  • ****
  • Posts: 675
  • Karma: 59
Re: Can I add a URL parameter to pre-fill in the donation amount.
December 01, 2014, 12:27:57 pm
Don't think it's supported to do this in core.

Agree that we did something similar years ago by inspecting $_GET probably via awful custom_php methods available then.

Should be pretty easy to do today with extension and form hooks.

Even easier just using JS to inspect the URL.
@xurizaemon ā— www.fuzion.co.nz

Chris Burgess

  • Ask me questions
  • ****
  • Posts: 675
  • Karma: 59
Re: Can I add a URL parameter to pre-fill in the donation amount.
December 01, 2014, 12:42:04 pm
Code: [Select]
function populateAmount() {
  var a = document.createElement('a');
  a.href = document.location;
  var amount = a.search.match(/amount=([0-9]+)/)[1];
  jQuery('input.search').val(amount);
}

^ demo in JS

  • visit https://gist.github.com/xurizaemon/31eeb8f50f2df6cf5603?amount=1234
  • copy code from gist
  • paste into browser console
  • look at search field now populated with amount from URL
@xurizaemon ā— www.fuzion.co.nz

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Can I add a URL parameter to pre-fill in the donation amount.
December 02, 2014, 04:14:25 am
Naice!

RachelWright - does this help?
Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviContribute (Moderator: Donald Lobo) »
  • Can I add a URL parameter to pre-fill in the donation amount.

This forum was archived on 2017-11-26.