Paypal form inside ASP.NET form

Greetings

I had a problem integrating a Paypal basket into my ASP.NET C # project. The problem is that the Paypal shopping cart is inside the FORM tag, so if I put it in my server form tag, it will not work.

It will look like this:

<body> <form id="form1" runat="server"> <form target="_self" action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="business" value=" MySecretEmail@hidden.com "> <input type="hidden" name="display" value="1"> <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_viewcart_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"> </form> </form> </body> 

Is there any way to prevent this? I search on google and here on Stackoverflow where I found this link: Fundamentals of the PairPI API PayPal API , but to be honest, this does not make sense to me since I am not a programmer.

Thanks!

+6
source share
6 answers

The easiest way to solve this problem is to use the PostBackUrl property of the asp: button. Using this method, ASP generates your JavaScript to process the external message.

This allows you to correctly render the form and does not require a workaround. Remember that since your code is already in the form tag, your PayPal items should not be wrapped with an additional tag.

eg.

 <input type='hidden' name='cmd' value='_cart'/> <input type='hidden' name='upload' value='1'/> <input type='hidden' name='business' value=' business@business.com '/> <input type='hidden' name='currency_code' value='aud'/> <input type='hidden' name='item_number_1' value='item number_1'> <input type='hidden' name='item_name_1' value='16x16 inch square canvas'> <input type='hidden' name='amount_1' value='70'> <input type='hidden' name='item_number_2' value='item number_2'> <input type='hidden' name='item_name_2' value=' 48x20 rectangular canvas'> <input type='hidden' name='amount_2' value='104'> <asp:Button ID="Button1" PostBackUrl='https://www.paypal.com/cgi-bin/webscr' runat="server" /> 

Hope this helps.

+10
source

Technically, your example is not valid HTML. In the long run, you can best rework this code to remove your “technical debt”. (See “Should not contain other form elements” in the element prohibition section of the W3C site for XHTML 1.0)

In the meantime, you can try submitting a nested form using jQuery .

1. Replace the submit button

 <button class="submit-button" id="submit-button">Submit Payment</button> 

2. Change the form tag

 <form id="nested-form" target="_self" action="https://www.paypal.com/cgi-bin/webscr" method="post"> 

3. Submit a form using jQuery

 <script type="text/javascript"> $('#submit-button').live('click',function() { $('#nested-form').submit(); }); </script> 

I have not had the opportunity to verify this, so please check and let me know if this works for you.

+1
source

Here is a very simple method. This is what I use exclusively so that I know with 100% certainty that it works.

  • Create a “false only” button for PayPal only.
  • User clicks this button (this is just an image)
  • This image has an onclick method that calls the 2-line javascript function (see below).
  • Put your “real” PayPal button form at the end of your page AFTER closing the form tag.
  • Paste it in the SPAN tag with style = "display: none;"
  • Add ID = "ppsubmit" to the "real" button image input
  • When the user clicks the false button, the onclick method calls the javascript function, which does just two things: a) changes the display of the range to the built-in one and b) automatically clicks the real PayPal button.

     <form id="form1" runat="server"> <!-- Here the image only "false" paypal button --> <input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_subscribeCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!" onclick="javascript:doPPform();" /> </form> <!-- this closes your asp.net form --> <!-- Here the hidden span with the real paypal button at the bottom of your webpage --> <span id="ppform" style="display: none;"> <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top"> <input type="hidden" name="cmd" value="_s-xclick"> <input type="hidden" name="hosted_button_id" value="xxxxx"> <input id="ppsubmit" type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_subscribeCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> <img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"> </form> </span> <!-- Here the 2 line javascript code when the user clicks the "false" button --> <script language="javascript" type="text/javascript"> function doPPform() { document.getElementById("ppform").style.display = "inline"; document.getElementById("ppsubmit").click(); } </script> 
+1
source

A quick fix is ​​to place the paypal form inside the iframe .

In the form element, change target="_parent" so that it returns to the parent page.

0
source

Why don't you make a page that uses a payment form, use MasterPage with the tag removed. I do this on all sites and it works without problems.

0
source

I discovered a problem with the PayPal button before I discovered that it was an ASP.NET problem. In the process of creating buttons and adding to my page, sometimes they will work, and sometimes not. Then I would have two identical buttons, and the second would work, but the first would not. Remove the first and then the button that would work. To get to the point, if I added a form tag in front of my PayPal button, the Paypal button works.

 <%-- simple form tag --%> <form action=""> </form> <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="business" value=" hughet_1335403121_biz@yahoo.com "> <input type="hidden" name="lc" value="US"> <input id="iptItemName" type="hidden" name="item_name" value="testBuyNow"> <input type="hidden" name="amount" value="10.00"> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="button_subtype" value="products"> <input type="hidden" name="no_note" value="0"> <input type="hidden" name="cn" value="Add special instructions to the seller"> <input type="hidden" name="no_shipping" value="2"> <input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted"> <input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> <img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"> </form> 

I understand this “hack fix,” and I'm not sure why this works. Curious if this works for others.

-1
source

Source: https://habr.com/ru/post/902836/


All Articles