views:

37

answers:

3

I'm am using ASP.NET MVC to create a page that posts to the Paypal sandbox. My form that posts to the Paypal site is nested inside a parent form. I am using Internet Explorer 7, and for some reason, the nested form posts to my local machine instead of the paypal site. If I add a copy of the same nested form directly after the first, the first one posts to localhost, and the second posts to where it is expected.

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>
    </title>
</head>
<body>
    <form name="aspnetForm" method="post" action="" id="aspnetForm">        
        <!--First form posts locally-->
        <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
            <input type="submit" value="Pay"/>
        </form>     

        <!--Second identical form posts to the expected destination-->
        <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">     
            <input type="submit" value="Pay"/>
        </form> 
    </form>

+8  A: 

Nested forms are not vaild, and therefore their behavior is undefined. You just cannot nest them. Only one form can submit at a time, though you can have multiple, unnested forms on a page (only the one of the corresponding submit button will be submitted, though).

Palantir
+1 - W3 notes on forms here: http://www.w3.org/MarkUp/html3/forms.html
Sohnee
A: 

Handle the button click event on the server side and post to the site from there. Nested forms are invalid xhtml.

Kendrick
A: 

Looks like I used the ASP.NET master page template instead of the ASP.NET MVC one. The ASP.NET template includes a form tag which is what created this nested form page. Using the ASP.NET MVC template fixed my problem by removing the nested forms altogether.