|
I've made a new friend. My new buddy Ron in Australia tried using my AWeber-to-DNN form converter for a PayPal button, and it didn't work because AWeber and PayPal don't generate similar enough code. He asked me how he could do the same kind of conversion for his PayPal buttons, and I converted one for him to show him how it's done. He's now a "happy little vegemite," as he put it.
Ron isn't the first person to ask me about converting PayPal buttons, so this weekend I decided to write a converter that works a lot like the AWeber/DNN converter, only for PayPal buttons. It was really easy because I was able to clone the AWeber converter and make a few tweaks for the idiosyncrasies of PayPal buttons.
By the way, the AWeber/DNN converter works fine on any ASP.NET page, not just within DNN. If you aren't working in DNN, you should just remove this part from the javascript:
theForm.__dnnVariable='';
The main difference between the PayPal button code and the AWeber button code is in how the companies chose to submit the form. AWeber uses a standard submit button, and PayPal uses an image button. Otherwise, the conversion is virtually identical.
Here's what the pre-converted code for a typical "buy now" button looks like:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="myname@mydomain.com">
<input type="hidden" name="item_name" value="Sample Item Name">
<input type="hidden" name="item_number" value="SAMPLEID">
<input type="hidden" name="amount" value="100.00">
<input type="hidden" name="no_shipping" value="0">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="weight" value="10">
<input type="hidden" name="weight_unit" value="lbs">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input type="image" src="images/buynow.gif" border="0"
name="submit" alt="PayPal - The safer, easier way to pay online!">
</form>
To make the example a little shorter and clearer, I'm using my own button image.
The post-converted code looks like this:
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="myname@mydomain.com">
<input type="hidden" name="item_name" value="Sample Item Name">
<input type="hidden" name="item_number" value="SAMPLEID">
<input type="hidden" name="amount" value="100.00">
<input type="hidden" name="no_shipping" value="0">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="weight" value="10">
<input type="hidden" name="weight_unit" value="lbs">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<a href="javascript:theForm.__VIEWSTATE.value='';
theForm.encoding='application/x-www-form-urlencoded';
theForm.action='https://www.paypal.com/cgi-bin/webscr';theForm.submit();">
<img src="images/buynow.gif" border="0"></a>
The javascript code should not really break across lines like I show it above. Everything in the href attribute should be one long string, but
I had to break it up for readability.
Here's what the PayPal button converter does to get from "pre" to "post:"
- Remove the form tag from around the input controls.
- Replace the <input type="image"> tag with an anchor (a) tag that wraps an image (img) tag and has the necessary javascript in the href attribute.
The only extra coding I really had to do was to extract the value of the src attribute from the image button so I could use it in the img tag. The rest of the code was very similar to the AWeber converter.
Here's a link to the new converter:
PayPal Button Converter for ASP.NET
If you have PayPal buttons that you want to use on an ASP.NET page, give the converter a try and let me know what you think!
Note that the technique I describe here and the code that the converter creates only works for one PayPal button on the page.
If you try to put multiple buttons of the same type on the page, you run into problems because they all use the same field names. The workarounds
for this problem include using an IFRAME tag for each button (in which case you don't need to do any conversion at all), or some intermediate-level JavaScripting to deal
with the multiple field problem.
By the way, just as the AWeber-to-DNN converter works for ASP.NET, the PayPal converter works for DotNetNuke, which is written in ASP.NET after all!
Visitor Comments
To submit your comments, click the "Please click here to send feedback" link below. |
|