Take the 2-minute tour ×

I have the following code that allows the person to choose the donation amount and download the file. At the moment this allows the person to put in 0 and download. I want to make the minimum 0.99. How could I make it compulsory to make a donation otherwise don't download. I appreciate your help.


echo "<p>Donate fixed amount to CharityName</p>
<form method='POST' action=''>
<select name='currency_code'>
<option value='EUR'>EUR</option>
<option value='GBP'>GBP</option>
<option value='USD'>USD</option>
<input type='text' name='donate_amount' value='0'>
<input type='submit' name='submit' value='Donate'></form>";

if(!empty($_POST['submit'])) {
// Form has been submitted
  if($_POST['donate_amount'] > 0) {
// Redirect to PayPal
header('Location: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&item_name=Donation for XXX&amount='.$_POST['donate_amount'].'&currency_code='.$_POST['currency_code'].'&business=mypaypalemail@here.tld&cbt=Download the file&return=http://link-to-the-file&cancel_return=http://back-to-my-website');
else {
// No donation amount entered - proceed to file directly
header('Location: http://link-to-the-file/');

share|improve this question
I was also wondering how I could include a google analytics code in this download link to track the download that was made –  Matt Hull Aug 17 '12 at 21:27
remove the header('Location: http://link-to-the-file/'); in your else and add error message there. –  Virendra Aug 17 '12 at 22:44
"Compulsory to make a donation"... I don't think you understand what a donation is. –  Waleed Khan Aug 19 '12 at 1:14
add comment

1 Answer

up vote 0 down vote accepted

See a sample:

    if($_POST['donate_amount'] >= 0.99) {
        // Redirect to PayPal
    } else {
        exit('Please donate at least $.99');

For Google analytics, I can't answer you, sorry.

share|improve this answer
Okay, I think I have put that together - thank you for your help. Is there a way of adding google analytics code to track the download? Adding in: <a href=”pdfs/my-file.pdf” target=”_blank” onclick=”_gaq.push(['_trackEvent','Download','PDF',this.href]);”>Download my file</a> –  Matt Hull Aug 18 '12 at 9:26
also, would I have to put 0.98, so that 0.99 is the minimum? As with 0.99 it seems to not redirect to Paypal. –  Matt Hull Aug 18 '12 at 9:30
For the Google analytics, would I be best to do this? : $(function(){ $('#submit').click(function(){ _gaq.push(['_trackEvent', '<?php the_title(); ?>', 'my action']); }); }); –  Matt Hull Aug 18 '12 at 13:32
Thank you for your help I really appreciate it –  Matt Hull Aug 20 '12 at 16:56
You are welcome! –  Gabriel Santos Aug 20 '12 at 17:28
add comment

Your Answer


