Consider the code below -
<form id="Form1" runat=server defaultbutton="cmdclick" style="height: 9%;">
<form action="https://www.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="XT4SGK2B4H954">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_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>
The inner form is not getting submitted. It refreshes the page on clicking on it.
What would be the better method?
Note : Project is in ASP.NET.
An ASPX page is like a giant HTML form and when you throw in another form without closing the ASP one you end up with nested forms.
To resolve the problem you need to close the ASP form before the PayPal button code starts or create a PayPal button as a URL and hyperlink it to some text or an image on your site.
The problem is that HTML does not allow nested form tags.
Please see my response to a similar question here. I describe an alternative approach to include PayPal buttons in ASP.Net pages.
Hope it helps.
I solve it by adding the paypal code in html page and view it in my asp.net page via iframe.
Related
I've created a paypal donation button from paypal business account with all default setting. I copy paste the html into my asp.net page, and it looks fine. The problem is when I click on the button simply nothing happen. Is this because I'm still on localhost? Will it be work and go to paypal page when I upload the website?
<form action="https://www.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="buttonId">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_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>
Your asp.net page probably already has a form tag on it and you may have placed the PayPal code inside that form, which won't work. Instead of using the form with the hidden fields that PayPal generated for you, you could just use a link with url parameters. Here's an example (make sure you replace YOUR_BUTTON_ID_HERE with your id):
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YOUR_BUTTON_ID_HERE">
<img src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" alt="PayPal - The safer, easier way to pay online!" />
</a>
Good afternoon. In your original example, no hosted button ID was provided:
<input type="hidden" name="hosted_button_id" value="buttonId">
PayPal buttons are hosted on your PayPal account, so in order for the checkout to appear, an ID must be present.
In order to locate the hosted button ID, log in to your PayPal account and go to Tools > PayPal Buttons. Click on the carat next to the button you are trying to add, and the button ID will display. Just substitute that value for "buttonId", and it should be working.
I'm trying to insert a paypal button using their code into the HTML tab of the wordpress wysiwyg editor. When I publish and view the source code in chrome, the form tags don't show and the button action does not happen when clicked.
The form tags do remain there in wordpress, however.
Any knowledge of why these wouldn't be carrying over? I've never had this happen, and it was working last week, same code, same project.
Could it be the newest wordpress upgrade?
It's weird because another button on another page of the same site, from paypal as well, works still..
Code from paypal:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="QLFJU8MHD2XCN">
<input type="image" src="http://www.spmoh.com/wp-content/uploads/2012/06/donate-now.png" 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>
The form elements are still there in the source code. I can think of two possible reasons why they are removed in the DOM view:
Invalid nesting of elements, for example h1 elements (that are block level elements) inside a ones. At a quick glance, I can't see anything on that page that could be causing it, though
JavaScript removing the elements afterwards (e.g. some rogue jQuery cleanup script).
I was provided the following code to integrate into my ASP.NET WebForms page:
<form action="http://www.google.com/cse" id="cse-search-box" target="_blank">
<div>
<input type="hidden" name="cx" value="partner-pub-8127518365728966:9snx3s9v6fx" />
<input type="hidden" name="ie" value="ISO-8859-1" />
<input type="text" name="q" size="25" /><br />
<input type="submit" name="sa" value="Search" class="formoutput"/>
</div>
</form>
<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&lang=en"></script>
However, I'm not sure how to do this because of the extra form element that this poses. Has somebody translated this to work with ASP.NET WebForms previously, and if so can you help me out?
Thanks!
Take a look here: http://am22tech.com/s/22/Blogs/post/2010/05/26/How-can-I-add-Google-search-box-to-my-website-on-master-page-with-aspnet.aspx
It's a bit of a hack but the idea is to do the following:
Place the search box in a separate HTML page
Modify the Target and Action properties of the form
Add an iFrame to your main page with the source of the above HTML page
The article is pretty detailed and, if you don't mind using an iFrame, then it should answer your question.
Update
Scott Mitchell has posted a very detailed article that does not use iFrames. It looks like more work to implement but may be the better choice.
URL: http://dotnetslackers.com/articles/aspnet/Implementing-Search-in-ASP-NET-with-Google-Custom-Search.aspx
Scenario:
I have a regular aspx page with a form.
When someone clicks a button the form submitted via post like normal.
HOWEVER. The page where the form resides is the default page(Default.aspx). So when someone goes to the site: http://site.com/ and submits the forms he gets redirected to http://site.com/default.aspx. I tried setting the action of the form to http://site.com/. However asp.net does not allow to use root urls with a POST.
So is there any workaround? Ajax is not an option.
Have you considered creating a plain HTML form? You would need to place your plain HTML form outside the ASP.Net runat=server form on your page.
<form id="form1" runat="server">
ASP.Net controls on your page go here
</form>
<form method="post" action="http://www.site.com">
<input type="text" name="input1" />
<input type="submit" name="input2" value="Submit" />
</form>
I'm trying to put the following Google generated search box code into a Master page on a site:
<form action="http://www.google.com/cse" id="cse-search-box">
<div>
<input type="hidden" name="cx" value="partner-pub-xxxxxxxxxx:u3qsil-l6ut" />
<input type="hidden" name="ie" value="ISO-8859-1" />
<input type="text" name="q" size="31" />
<input type="submit" name="sa" value="Search" />
</div>
</form>
<script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cse-search-box&lang=en"></script>
The problem, I believe, is something to do with the form tags. I've tried putting this code inside a user control and embedding that in the master page but no luck yet...
Do you by any chance have a "form runat=server" wrapping around where your user control is being placed?
That would cause a problem.
ASP.NET likes to enclose the entire page with a Form tag, and you can't nest form tags...So move it outside of the <form runat="Server"> tag and you'll be fine.