Media Image
reforms
Publish Date
Filed Under

I had a friend ask if I could create a donation/membership page for their non-profit using PayPal.  The site is built in Joomla! 3.x so I naturally thought of an excellent extension like JoomDonation.  However, they wanted a number of tweaks that meant modifying the extension which I hesitate to do.  Enter RSForm! Pro.  It's pretty much been my go-to form builder on any Joomla! site I've built over the years.

 

Basic View:

The referenced media source is missing and needs to be re-embedded.

 Requirements:

  • Select a pre-set amount or enter a custom donation amount.
  • One-Time or Recurring donations (recurring donations required a PayPal account - users would manage them there...)
  • Recurring Donations on a Monthly, Quarterly, Semi-Annual or Annual basis.
  • Recurring donations would be empty for on-going donations, or at least 2, since 1 throws an error at PayPal.  (RSForm has a "range" validation feature).
  • Clean looking.
  • If you clicked on the Custom Donation Amount a field appears, allowing the amounts to be a required field, even if a donor chose the custom option.

Code: (download at the bottom of the article)

The magic happens upon form submission.  The php tests for all the variables then sends the appropriate link to PayPal. (Please don't write to me and tell me my code could be improved... I know it could. - I haven't done any coding in years lol).

/*Recurring Donation */
if ($_POST['form']['recurring'] == 'Recurring')
{
$business = 'design@navigatetomorrow.com';;
/* getting the donation name */
if ($_POST['form']['other'][0] != '') {$item_name = str_replace($replace, $with, 'Custom Amount');}
if ($_POST['form']['membership'][0] != '0') {$item_name = str_replace($replace, $with, '{membership:text}');}
/* getting the donation amount */
if ($_POST['form']['membership'][0] != '0') {$total = str_replace($replace, $with, '{membership:value}');}
/* getting duration and frequency for PayPal */
$duration = str_replace($replace, $with, '{duration:value}');
$frequency = str_replace($replace, $with, '{frequency:value}');
if ($frequency == 'Q') {$p3 = '3'; $t3 ='M';}
if ($frequency == 'Y') {$p3 = '1'; $t3 = 'Y';}
if ($frequency == 'S') {$p3 = '6';$t3 ='M';}
if ($frequency == 'M') {$p3 = '1';$t3 ='M';}
/* PayPal variables set */
$currency_code = 'USD';
$a3 = $total;
$src = '1';
$srt = $duration;
$no_note = '1';
/* upon successful completion of the donation, RSForm will update the status from Pending to Accepted */
$notify_url = JURI::root().'index.php?option=com_rsform&formId='.$formId.'&submission='.$SubmissionId;
$url= 'https://www.paypal.com/cgi-bin/webscr?cmd=_xclick-subscriptions&business='.urlencode($business).'&item_name='.urlencode($item_name).'&currency_code='.urlencode($currency_code).'&a3='.urlencode($a3).'&p3='.urlencode($p3).'&t3='.urlencode($t3).'&src='.urlencode($src).'&srt='.urlencode($srt).'&no_note='.urlencode($no_note).'&notify_url='.urlencode($notify_url);
$app = JFactory::getApplication();
$app->redirect($url); 
exit(); 
}
/* One Time Donation */
if ($_POST['form']['recurring'] == 'One Time')
{
if ($_POST['form']['membership'][0] != '') {$item_name = str_replace($replace, $with, '{membership:text}');}
if ($_POST['form']['other'][0] != '') {$item_name = str_replace($replace, $with, 'Custom Amount');}
if ($_POST['form']['other'][0] != '') {$total = str_replace($replace, $with, '{other:value}');}
if ($_POST['form']['membership'][0] != '0') {$total = str_replace($replace, $with, '{membership:value}');}
$currency_code = 'USD';
$a3 = $total;
$p3 = '0';
$t3 = '1';
$src = '0';
$no_note = '1';
$notify_url = JURI::root().'index.php?option=com_rsform&formId='.$formId.'&submission='.$SubmissionId;
$url='https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=design@navigatetomorrow.com&item_name=One+Time+Donation&amount=' .$total .'&currency_code=USD&notify_url='.urlencode($notify_url);
$app = JFactory::getApplication();
$app->redirect($url); 
exit(); 
}

Test It Out

Feel free to test out the form - you can even send a donation if you'd like :) {rsform 4}

Download

To use this code you must have a Joomla 3.x website (minimum) and a copy of RSForm! Pro.

Download