20.9. How to display HTML forms in a block: Paypal

A lot of sites have a block, asking for donations through PayPal. It is easy to construct your own, all you need is get an account from PayPal, then construct an HTML form that contains your data, for example:

Help  keep our web site online with a donation!
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="My email">
<input type="hidden" name="item_name" value="My Homepage">
<input type="hidden" name="amount" value="10.00">
<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="image" src="https://www.paypal.com/images/x-click-but04.gif" 
       border="0"
name="submit" alt="Make payments with PayPal - it"s fast, free and secure!">
</form>

The meaning of the form fields is the following:

cmd:

Must be set to "_xclick" (required).

business:

This is your PayPal ID, or email address, where payments will be sent. This email address must be confirmed and linked to your Verified Business or Premier account. (required).

item_name:

Description of donation (maximum 127 characters). If omitted, donor will see a field in which they have the option of entering an Item Name (optional).

amount:

The price or amount of the purchase, not including shipping, handling, or tax. If omitted, this value will be editable by the buyer at the time of purchase (optional).

no_note:

Including a note with payment. If set to 1, your customer will not be prompted to include a note. If omitted or set to 0, your customer will be prompted to include a note (optional).

currency_code:

The currency of the payment. Defines the currency in which the monetary variables (amount, shipping, shipping2, handling, tax) are denoted. Possible values are USD (U.S. Dollar), EUR (Euro), GBP (Pound Sterling), CAD (Canadian Dollar), JPY (Yen). If omitted, all monetary fields will be interpreted as U.S. Dollars (optional).

tax:

Transaction-based tax override variable. Set to a flat tax amount you would like to apply to the transaction regardless of the buyer s location. If present, this value overrides any tax settings that may be set in the seller s Profile. If omitted, Profile tax settings (if any) will apply (optional).

TipPayPal hyperlink variables
 

There are many more hyperlink variables that you can use in your PayPal block, covering all aspects of a donation transaction. You should consult the PayPal Donations Manual, to learn about all the possibilities!

Figure 20-12. PayPal donation button

PayPal donation button

Pasting the code above into your website would generate a button that looks like Figure 20-12. To create a block out of this HTML Form, all we have to do is add the obligatory check for the block name, transform all lines to strings and append them to the $content variable, taking care to escape all double quotes between the string quotes:

<?php
if (eregi("block-Donations.php",$PHP_SELF)) {
    Header("Location: index.php");
    die();
}
$content  =  "Help  keep our web site online with a donation!";
$content  .= "form action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\">";
$content  .= "input type=\"hidden\" name=\"cmd\" value=\"_xclick\">";
$content  .= "input type=\"hidden\" name=\"business\" value=\"My email\">";
$content  .= "input type=\"hidden\" name=\"item_name\" value=\"My Homepage\">";
$content  .= "input type=\"hidden\" name=\"amount\" value=\"10.00\">";
$content  .= "input type=\"hidden\" name=\"no_note\" value=\"1\">";
$content  .= "input type=\"hidden\" name=\"currency_code\" value=\"USD\">";
$content  .= "input type=\"hidden\" name=\"tax\" value=\"0\">";
$content  .= "input type=\"image\" src=\"https://www.paypal.com/images/x-click-but04.gif\"
              border=\"0\" name=\"submit\" 
              alt=\"Make payments with PayPal - it"s fast, free and secure!\">";
$content  .= "/form>";
?>

Put the above code in a file called block-Donations.php in the blocks folder. Then, just activate and position the block from the blocks management link in the administration panel.

Figure 20-13. PayPal donation block.

PayPal donation block.

Depending on your theme, the block will look as in Figure 20-13. You can experiment with various button images from the PayPal site. For more information on donations with PayPal, see the PayPal Donations Manual.