Adding A PayPal Buy Now / Donate Button In Umbraco

Something that should be so simple… *SIGH*… I had a moment earlier, trying to add a donate button to an Umbraco site I have just finished.  I just grabbed the code from the PayPal site

https://www.paypal.com/cgi-bin/webscr?cmd=_pdn_xclick_techview_outside

Changed the values to what I needed (TIP: If you leave out the ‘amount’ value it will prompt people to add in a value and perfect for a donation button) and put it in my site, published the page and it didn’t work – Even weirder it had stripped out my form tag just leaving the values.[more]  I then realised I was nesting a <form> tag inside another form tag the .NET runat=server <form> tag that Umbraco was using, and it stumped me for a while I have to say!  I read other people saying you can add another ‘dummy’ form tag above it, and it will strip out the first tag and leave the second – I don’t like this idea of bloating my page with extra redundant code, so I came up with the following.  You can use the hidden values as QueryString values and it works exactly the same – So the following as taken from the PayPal site:

<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="me@mybusiness.com">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="item_name" value="Teddy Bear">
<input type="hidden" name="amount" value="12.99">
<input type="image" src="http://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>

Would become

<a href=”https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=me@mybusiness.com&currency_code=USD&item_name=teddy bear&amount=12.99”>Donate Via PayPal</a>

Hope this helps other people going through the wasted time I had of trying to figure out what I had done wrong.

1 comment for “Adding A PayPal Buy Now / Donate Button In Umbraco”

  1. Posted Monday, October 19, 2009 at 5:39:53 PM

    I was in the same boat and refused to use that &quot;double form tag&quot; hack. Here's a way to do this and avoid the use of hidden fields:

    http://www.codersbarn.com/post/2008/03/08/Solution-to-ASPNET-Form-PayPal-Problem.aspx

    Rgds,
    Anthony :-)

Post a comment