Sign In  |  Register
 
 
DotNetNuke Support Forums
How To: Add PayPal Buy Now Buttons to DNN
Last Post 22 May 2007 02:24 AM by eclayf. 9 Replies.
Printer Friendly
Sort:
PrevPrevNextNext
Please Register to post a reply.
Another benefit of registration is the ability to subscribe to and recieve notifications of new posts.
AuthorMessages
John Mitchell
Administrator
Veteran Member
Veteran Member
Send Private Message
Posts:4133
Avatar

--
21 Feb 2007 12:40 PM  
You can do this with a simple javascript trick.

Step 1. Remove the <form>> </form> tags from your PayPal "Buy Now" code.

Step 2. Add 
          onClick="this.form.action='https://www.paypal.com/cgi-bin/webscr';   
                      this.form.submit();" 

      to the buy now input button.

Step 3. Paste what is left into the html module
 
What it does is change the action for the Form that is already embedded into the DotNetNuke default.aspx page.


Here is an an example:
 
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

< input type="hidden" name="cmd" value="_xclick" >
< input type="hidden" name="business" value="payments@snapsis.com">
< input type="hidden" name="item_name" value="Buy John a Beer">
< input type="hidden" name="item_number" value="Beer">
< input type="hidden" name="amount" value="1.00">
< input type="hidden" name="no_shipping" value="2">
< input type="hidden" name="no_note" value="1">
< input type="hidden" name="currency_code" value="USD">
< input type="hidden" name="lc" value="US">
< input type="hidden" name="bn" value="PP-BuyNowBF">
< input type="image"
   onClick="this.form.action='https://www.paypal.com/cgi-bin/webscr';this.form.submit();"
src="https://www.paypal.com/en_US/i/btn/x-click-but23.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
< img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
 
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
You can find more advanced ideas in this thread on the asp.net forums.
eclayf
New Member
New Member
Send Private Message
Posts:19

--
25 Apr 2007 10:09 AM  
John, one question about the javascript portion of this. How would one modify it to include "target=paypal" in the code so a new windiow opens? This slight modification would allow a lot of people to integrate the complete PayPal shopping cart, not just the "buy now" function.

Clay
John Mitchell
Administrator
Veteran Member
Veteran Member
Send Private Message
Posts:4133
Avatar

--
25 Apr 2007 10:13 AM  
Hi Clay.
You would do that by changing the onclick part like this:

onClick="this.form.target='_blank';this.form.action='https://www.paypal.com/cgi-bin/webscr';this.form.submit();"
praisecards
New Member
New Member
Send Private Message
Posts:1

--
13 May 2007 03:02 AM  

Thank you for the info John and I have worked on it a bit in my site.  It "seems" to cause a problem and some odd behavior.

I added two text/html modules to a page, added a differing product to each module, with this code to submit the products.  Works fine, but does a few wierd things.

1.) If I use this code to submit a product to a PayPal standard cart, then try to use "settings" from the control panel on the same page with the javascript added in a text/html module, it opens a new cart window and adds another product to it. If I click "Add" from the control panel, same wierd behavior.

2.) If I am logged in as an admin or host, clicking the button to add to the cart will actually open two carts, the first one with one product added, the second with two products added.

3.) If I have NOT previously clicked a button for a product, then the control panel "settings," "add" and so on work fine, until I click a button once, then the behavior begins as in "1.)" here above.

I am not sure what to make of all this.  Oh, by the way, the "continue shopping" at the bottom of the paypal cart doesn't work either (no longer minimizes cart) and any additional items open new/additional cart windows. 

I have tried target="_blank" and target=_paypal to name the target window to eliminnate duplicate windows with no joy. In classic .asp none of this behavior happens and I am sort of at a loss as to how or why this is occuring in a DNN page with 4.4.1 under .net 2.0.

Guess I might have to study Asp.Net 2.0 some more to get a better handle on all this.

Any Ideas?

Clay

John Mitchell
Administrator
Veteran Member
Veteran Member
Send Private Message
Posts:4133
Avatar

--
13 May 2007 07:44 AM  
Hi Clay,
That is happenning because we are actually changing the original page so that it will post to PayPal instead of posting to itself which it is supposed to do for all the other buttons/links on the page.

To fix that you can add code to change the form action back to it's orignal state after the post to PayPal.
onClick="var fa = this.form.action;this.form.target='_blank';this.form.action='https://www.paypal.com/cgi-bin/webscr';this.form.submit();this.form.action=fa;this.form.target=''"

You will also have trouble if you try to put more than one product on a page because when the form submits it will be submitting both products at the same time. There is no way around that without some more complex coding.
eclayf
New Member
New Member
Send Private Message
Posts:19

--
13 May 2007 03:29 PM  

Interesting stuff.  Thank you again John. 

The "more complex" coding you speak of,,, is that being used in the various store modules around?  I suppose it is and I could find examples of it there.  Reason for all this line of questioning is that I am working on an idea and will be using the core Repository module when I figure out all the quirks of what I am after.

Once I have a few of these "quirks" figured out, repurposing existing code to make "simpler" module type functions available through the Repository will be a lot of fun for me.

Thanks again,

Clay

John Mitchell
Administrator
Veteran Member
Veteran Member
Send Private Message
Posts:4133
Avatar

--
13 May 2007 06:44 PM  
Yes, listing more than one module is what some of the other store modules provide. If you look in that thread for more advanced ideas in my origianl post you can see some further discussion along those lines.

eclayf
New Member
New Member
Send Private Message
Posts:19

--
17 May 2007 07:18 PM  

John, first I want to thank you for all the input.  It has greatly helped me in my efforts and increased my understanding of the issues of working with DNN in "new" or different ways than it was intended to function, while keeping all the wonderful things that make up DNN.

I have finaly managed to make a form post from a DNN page to a separate page, and allow multiple posts to the same page that way.  Now I have what I think will probably be the last question on this topic before I start to repurpose some DNN functions in interesting ways.

You are using Javascript to rename, then post and then reset the Form on the page in the code above by using a Javascript variable.  Is there a simple way, in Javascript to increment that varialbe on the page?  

In "classic" .asp I used to be able to declare the variable in the page, then declare that it would increment each time found in the page.  Such a way of declaring the "var = " statement you use would be a very simple way of allowing multiple onclick events with different varialbes for the name.

Something like "var = a" then increment it with "var = a+1" so that if I loaded items or data from a database, each time a new record loaded, the variable automatically incremented by "1" so that all of the "forms" had different names.

Is this possible in using Javascript in DNN?  If so, it should be possible to have multiple forms on one page each submitting under a different "from" varaible in the onclick event handler.

Am I correct, and how would that look?

Clay

John Mitchell
Administrator
Veteran Member
Veteran Member
Send Private Message
Posts:4133
Avatar

--
17 May 2007 08:25 PM  
Hi Clay, you're welcome, and I'm glad to help.

The main thing about ASP.Net over classic ASP is that you can have one and only one form per page.
If you try to put more than one form on the page then you will get an exception thrown back when the page loads on the server.

You could build multiple forms on the client using Javascript, but it's a tricky situation especially if you want your main ASP.Net buttons to work.

One way around all of this is to put your forms in a classic ASP page just like you would have done before, and then use an IFRAME to include it inside your ASP.Net page. Doing this will seperate the two pages while still giving you the feel that they are one.
eclayf
New Member
New Member
Send Private Message
Posts:19

--
22 May 2007 02:24 AM  

Hi again John,,,, I have been doing a very dangerous thing,,,,, thinking about all this and I have one, possibly two more questions, depending on your answer.

I see that in the string we are setting the following:

var fa = this.form.action;this.form.target='_blank';this.form.action='https://www.paypal.com/cgi-bin/webscr';this.form.submit();this.form.action=fa;this.form.target=

What would be wrong with simply adding an additional " this.form.value='(html form inputs here)'; " previuos to the action assignment in the  j a v a s c r i p t and using them as part of the script, removing them from before the script?

Please Register to post a reply.
Another benefit of registration is the ability to subscribe to and recieve notifications of new posts.


Active Forums 4.1
Visit our Store for great DotNetNuke Modules and Skins
DotNetNuke CSS Menu 3.4.1 (single use)

Item codeCSSNM33SU
AuthorJohn Mitchell
Base Price$39.00
Product Information 
DotNetNuke CSS NavMenu 3.4.1 (Developers)

Item codeCSSNM33DEV
Base Price$149.00
Product Information 
DotNetNuke Performance Caching & Compression - PageBlaster 3.4.5 - Professional Edition

AuthorJohn Mitchell
Base Price$59.00
Product Information