Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form inside of a form

Status
Not open for further replies.

jammer1221

Programmer
Jul 30, 2003
352
US
Hey All,

I was wondering if anyone knows a quick and easy way to fix this problem?

Code:
<form method="post" action="...">
<input .../>
<input .../>
  <form method="post" action="...">
   <input .../>
   <input type="submit" />
  </form>
<input .../>
<input type="submit" />
</form>

Ok, so hopefully my example makes sense, but, when I submit the nested form it submits the data to outer form. The second submit button doesn't even work.

I can probably make a javascript solution to this, but was wondering if there was an HTML solution?

Thanks,
Matt
 
You can't nest Forms. Why would you even want to?
It certainly wont validate, and is most likely to cause problems in different browsers.

What is it you want to accomplish by nesting them??

Can't you have One form after the other???

What is the behavior you are expecting?

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks for the info. That's what I guessed.

At the moment I don't care about validation, IE only. It's for a Windows XPe application.

I could move the forms, but I don't really want to as it will mess up my layout. Currently, I have a page full of information that is actually inputs so the user can change the data if they want to. In the middle of my page is my nested form in which is an area to leave comments.

As to what behavior I was expecting...it's kind of obvious.

Thanks for the help,

Matt
 
It would be better to keep the forms separate and then control where the content is on the page with CSS. That way you can have the 2 different forms, place the content where you want, and still validate (just saying you are only coding for IE is a very weak argument [and a very weak browser]).

If you need help positioning with CSS, I would suggest Googling it for loads of examples.

Einstein47
For best results: hand wash in cold, tumble dry low.
For not so good results: drag through puddles, pound on rocks, air dry on tree branch.
[&#91;]Starbase47.com]
 
If you shows your layout, maybe we can come up with something to get it the way you want it to look, without nesting the forms.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I can think of no reason why you would ever need to nest forms from any perspective.

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
Exactly, but since the OP seems to think so, I was suggesting he shows us his layout so we may advise on how to place his forms to achieve the layout.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Einstein47,
FYI, nested forms do validate in XHTML 1.0 Transitional. Although you may think my argument for IE only code is weak, I disagree in this case. I am developing a web application for 30 Windows XPe units. So how it looks and works on my screen is how it will look and work on their screens.

Vacunita,
I appreciate your offer to take a look at my code, although I must decline. I do appreciate all your help!

Thank you all for you advice and insights to my problem. It was much appreciated!

Matt
 
Nested forms are wrong. simple as that.
Who is to say that when the 20 XPe boxes get an update you app will still work?
Why not do it correctly and bulletproof your work?

How does the submit action work? How does it know which form you are submitting?

I'm also pretty certain that nested forms will not validate against XHTML 1.0 Transitional or any XHTML DOCTYPE. Which validator are you using because the W3C validator chokes on nested forms.

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
Yes, I agree with you that nested forms are wrong because they do not work. However, these boxes will never get updated and I am certain of that.

Relating to bullet-proofing my work, I understand that is what all of you guys are saying and I realize for regular web development it is a good idea...a great idea. But, this is not regular web development.
And for validating I stand corrected. I validated this code through the direct input at the W3C and it failed.
Code:
<!doctype html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html>
<head>
<title>adsf</title>
</head>
<body>
<form action="go.php" method="get">
<input type="text" />
<form action="go.php" method="get">
<input type="text" />
<input type="submit" />
</form>
<input type="submit" />
</form>
</body>
</html>
Strange though, when I upload my code to the validator it validates. Albeit my page is quite a bit longer than the code above and may have possibly found one of the validator’s limitations.

Matt
 
Yes, I agree with you that nested forms are wrong because they do not work. However, these boxes will never get updated and I am certain of that.
Then quit jerking around. Put it in a separate form that's positioned relatively so it appears to be in or near the other form.

Or...leave it off altogether. However, if it is part of the approved specification, it might be a good idea to have a form that actually works.

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
How about this, since it is for an internal application. Use just one form. But when you squeeze the button of what you experience as the subform, have javascript change the action attribute of the form (and any other attributes you need changing) and submit the form. That way it would be like having two different forms. A JS-less solution would be to simply determine on the processing page which button was clicked and act according to that -- but that might involve too much tampering with whatever you already have.

___________________________________________________________
[small]Do something about world cancer today: PACT[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top