Getting a "normal" HTML form to work inside the server-side form tag

D

Deane

I've run into this problem on many occasions --

I need to have the server side form tag on my Web form, of course.

But I also need to have *another* form on the page that posts to a URL
totally out of my control. I can think of three situations off the
top of my head.

In one case, it was a login to the client's PeopleSoft system.
In another, it was a PayPal form.
In another, the form posted to the client's Google Mini install.

What's the solution for this? I haven't found a good one yet. How do
you get a "traditional" (non server-side) HTML form to work within the
server-side form tag?
 
S

Steve C. Orr [MCSD, MVP, CSM, ASP Insider]

A form cannot be within another form. This is against the rules of HTML.
You can have more than one form as long as one of them is a "traditional"
(non server-side) HTML form as you've specified. Just don't nest them.
Make sure there is no runat="server" attribute for your traditional HTML
form.
 
B

Brandon Gano

Forms cannot be nested, so there is no way to have a client-side form inside
a server-side form. There are a couple other options that might work for
you, though.

1) Don't nest the forms. Only server-side controls need to be contained
within a <form runat="server" /> tag. If all of your server-side controls
are above or below the client-side form, you can do something like:

<html>
<body>
<form runat="server">
...
</form>
<form action="...">
...
</form>
</body>
</html>

2) The other option requires the use of JavaScript to change the forms
action when you click a link/button. Something like (not tested):

<html>
<head>
<script type="text/javascript">
function SubmitForm()
{
var form = document.getElementById('MyForm');
if (form)
{
form.action = 'new/url';
form.submit();
}
}
</script>
</head>
<body>
<form runat="server">
...
<input type="submit" value="Click" onclick="JavaScript: SubmitForm();" />
</form>
</body>
</html>

3) There is also a way to set the server-side form to post back to a
different URL. I don't recall the syntax to do that, but I'm sure someone
else in the group can help there.
 
D

Deane

Sadly, it appears that I'm thoroughly screwed here.

I have server-side controls both above and below where this other HTML
form needs to go. So the whole thing needs to go in a server-side
form tag. And you can't have more than one server-side form tag, so
it's not like I can "shut it off," do the normal form, then turn it
back on again.

Ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,743
Latest member
WoodrowMea

Latest Threads

Top