bingles
bingles

Reputation: 12203

Internet Explorer Nested Form Post

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>

Upvotes: 5

Views: 2943

Answers (3)

bingles
bingles

Reputation: 12203

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.

Upvotes: 3

Kendrick
Kendrick

Reputation: 3787

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

Upvotes: 0

Palantir
Palantir

Reputation: 24182

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).

Upvotes: 11

Related Questions