Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is nested <form> possible?

in a content page of an asp.net web page, i would like to include the "paypal" button "Pay Now".

So, i've a master page, and a content page. In my content page i copy-paste paypal code. In particular i use a "modalpopupextender" to permit my user to buy the object. The problem is... it not work. So my hypotheses are:

  1. I'm not sure, but i think i can't use a nested <form action>
  2. If not the first, maybe i can't use a <form action> into a modal popup ?

someone can suggest me an "elegant" solutions to solve this ? Thank you ...

EDIT: in particular, what i'm trying to do is to permit to sell from a website. I've a master page, and a content page. Obviously in master page i've the classical "form action" . Then i'm gone to paypal and got this code: "

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<table>
<tr><td>
    <input type="hidden" name="on0" value="Annuncio Premium">Annuncio Premium
</td></tr>
<tr><td>
    <select name="os0">
        <option value="Premium 1">Premium 1 €1,00</option>
    </select>
</td></tr>
</table>
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="encrypted" value="-----BEGIN ">
<input type="image" src="https://www.paypal.com/it_IT/IT/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal - Il sistema di pagamento online più facile e sicuro!">
<img alt="" border="0" src="https://www.paypal.com/it_IT/i/scr/pixel.gif" width="1" height="1">
</form>

So i've pasted it into my content page ... as it... without changing. In particular i've pasted it, into a panel, that will show whith a "modalpopupextender". It works. But what it not work is when i click the paypal "Buy Now" button. My web page don't redirect to paypal, modalpopup disappears and nothing happens.

like image 747
stighy Avatar asked Jul 04 '10 19:07

stighy


People also ask

Can we have a form within a form?

You are not allowed to nest form elements. If the forms were separate (not nested) you can submit a different form using the form attribute on an input.

How do you nest a form element?

Nesting means putting an element between the opening and closing tags of another element. So you'll want to put the <input> between the <form> and the </form> .

Can we make form inside form in HTML?

No, the HTML specification states that no FORM element should contain another FORM element.


3 Answers

I had this exact issue too and couldn't believe that PayPal had not provided some sort of solution for .NET developers!!

Here is how I solved it:

<asp:ImageButton ID="btnPayNow" runat="server" ImageUrl="myPayPalButton.jpg" 
 PostBackUrl="https://www.paypal.com/cgi-bin/webscr" OnClick="btnPayNow_Click"/>

Use an ImageButton or normal button and simply remove the form tags for the PayPal code, leave in the hidden input fields and the data will be posted to the PayPal url!

Nice and easy :)

Ps. The method 'btnPayNow_Click()' does nothing, signature exists but there is no logic in the code I have.

like image 61
Dalbir Singh Avatar answered Sep 28 '22 02:09

Dalbir Singh


You are quite correct, in that you cannot nest <form>s.

Nor can you use the form action to create a popup - the action attribute is the url to which the form posts to.

You can, however, have many <form>s on the page, so long as they are not nested. Perhaps that will solve you issue.

Can you please describe exactly what you are trying to achieve? It is not clear from your question what the problem is.

like image 39
Oded Avatar answered Sep 28 '22 02:09

Oded


If I understand the question correctly, you are trying to create a dynamic HTML popup window which contains a PayPal form. You are having problems because the popup contains a form, but the HTML for the popup is already contained within a form.

If the problem you are experiencing is what I described above, the solution is fairly simple. You need to move all of the HTML for the popup outside of the exiting form element. If you are using CSS to properly lay out your site, it should be possible to display your dynamic popup wherever you need to on the page using relative or absolute positioning. The HTML for the popup need not be contained within another form. It may also be possible (perhaps even necessary) to put the contents of the popup into an iframe, which can be submitted entirely independently from the rest of the page. The semantics of how your popup works would depend on how you need your page to function.

So, to be clear...it is not possible to nest form elements. However, it is also not necessary to accomplish your needs.

EDIT:

To improve the answer above in light of the updated question. You can have multiple content panels on a master page. It should be entirely possible to create another content panel that is outside of your form element in your master page...and place your modal popup inside of this alternative content panel. My above answer would then still apply, as you no longer have nested forms.

like image 45
jrista Avatar answered Sep 28 '22 01:09

jrista