|< Day Day Up >|
Extend your donation system by allowing users to be recognized for their contributions .
[Hack #79] shows how to display donation goals for your web site with the intention of encouraging more and larger contributions. This hack shows how to recognize your donors for their contributions by displaying a list of the five most recent donors, the amount they donated, and a small note if the donor chooses.
7.20.1 The Donation Button
The donation button needs to be modified to present donors with two fields. The first asks whether the donor would like to have her name displayed on the web page. The second allows her to enter a short note if she wishes. As with a Buy Now button, the optional button variables on0 , os0 , on1 , and os1 are used to pass the donor's answers along to PayPal.
This donation button collects the information we need. (Note the similarity to the button code in [Hack #79] .)
<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="business" value="firstname.lastname@example.org"> <input type="hidden" name="item_name" value="Donation"> <input type="hidden" name="item_number" value="Donation-001"> <input type="hidden" name="no_note" value="1"> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="tax" value="0"> <input type="hidden" name="on0" value="Display name on donors page"> Do you want your name displayed on the "recent donors" page? <select name="os0"> <option value="Yes" selected>Yes</option> <option value="No">No</option> </select> <br> <input type="hidden" name="on1" value="Public note for donors' page"> Note for "recent donors" page (optional): <input type="text" name="os1" maxlength="255"> <input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but21.gif" border="0" name="submit"> </form>
When this form is submitted to PayPal by your donor, it passes the values for the optional fields along to PayPal, where the choices are displayed on the Confirm Your Payment page. This gives your donors a chance to reread the choices and use the Cancel button if they made a mistake.
7.20.2 The Database Table
The database schema for this hack is based on [Hack #82] and [Hack #83] . Those hacks cover recording the payment information and the payment detail information.
To store the donors' recognition choices, you need to add two fields to your database. You could create a new table for this information, but for simplicity, this example assumes you have added two fieldsnamed ShowName and DonorNote , of types integer and text, respectivelyto the tblPayments table, as shown in Table 7-4.
Table 7-4. A database table to track the donations you receive
7.20.3 The IPN Page
Your IPN page functions much like the IPN page described in [Hack #82] . However, you need to insert two new field values, one that indicates the donor's choice whether to display her name and one to hold the donor's note:
'Create new variables and populate them Dim ShowName Dim DonorNote If Request.Form("os0") = "Yes" Then ShowName = 1 Else ShowName = 0 End DonorNote = Request.Form("os1")
Include these values in the SQL statement to insert the values into the database.
INSERT INTO tblPayments (payer_email, payer_id, payment_status, txn_id, mc_gross, mc_fee, payment_date, first_name, last_name) VALUES ('" & payer_email & "', "' & payer_id & "', '" & payment_status & "', '" & txn_id & "', " & mc_gross & ", " & mc_fee & ", '" & payment_date & "', '" & first_name & "', '" & last_name & "', " & ShowName & ", '" & DonorNote & "')
7.20.4 The Donation Page
Now that you have the donation data flowing into your database, you can use it on your Donations page. Query the database table for the five most recent entries:
SELECT TOP 5 first_name, last_name, mc_gross, ShowName, DonorNote FROM tblPaymnets ORDER BY Id DESC
Once the query has been made, iterate over the five records and display each one, substituting Anonymous for any donors who choose not to be acknowledged publicly :
<% While NOT rsDonation.EOF %> <br> Donor: <% If rsDonation("ShowName") = 1 Then 'Show the name %> <%=rsDonation("first_name")%> <%=rsDOnation("last_name")%> <% Else 'Do not show the name %> Anonymous <% End If %> Amount: <%=rsDonation("mc_gross")%> <% If rsDonation("DonorNote") <> "" Then 'Note is not empty, show note %> Note: <% rsDonation("DonorNoate")%> <% End If %> <br> <% rsDonation.MoveNext( ) End %>
7.20.5 Hacking the Hack
You can encourage more donationsand donations of higher valuesby displaying lists of the most generous and the most recent donors.
Query the database for the top five donations by amount, sorted with the largest donation first:
SELECT TOP 5 first_name, last_name, mc_gross, ShowName, DonorNote FROM tblPaymnets ORDER BY mc_gross DESC
The code to display this information is identical to the code used in the previous section of this hack.
|< Day Day Up >|