Solved

2 forms on one html page - how?

Posted on 2003-11-18
7
244 Views
Last Modified: 2010-04-09
i have one form which spans from the top of my page to the bottom and within that another small form. prob is when i have them both on the same page and u hit either submit button, its not posting the right action. ie: form 1 on submit posts to the address of form 2. what tags would i put in to make sure they go to the correct urls of each.

big form

<form method="post" action="http://www.dfg/order.asp" onsubmit="return validateForm(this)" id=form1 name=form1>

-----------------
small form within above form tags

<form action="mailinglist.cgi" method="post">
  <input type="hidden" name="action" value="subscribe">

pls show exactly where code goes. thanks.
0
Comment
Question by:flyingknight
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 5

Expert Comment

by:ho_alan
ID: 9776207
u may rename the submit button, see if it helps.

eg.

<form name=bigForm>
<form name=inForm>
<input type=submit name=iSub value=submit>
</form>
<input type=submit name=bSub value=submit>
</form>
0
 
LVL 2

Expert Comment

by:incongruent
ID: 9776413
I haven't tested this code, but I think it should do the trick:  note that you use input type=button and not input type=submit.


<head>
<script language=Javascript>
function submitThis(whichOne)
{
  if(whichOne=='outer')
     document.form1.submit();
  else if(whichOne =='inner')
     document.form2.submit();
}
</script>
</head>
<body>
<form method="post" action="http://www.dfg/order.asp" onsubmit="return validateForm(this)" id=form1 name=form1>
..
..
<input type="button" name="goForm1" value="Submit Outer" onClick="submitThis('outer');">
..
..
<!--use input type=button instead of input type submit for both forms-->
<form action="mailinglist.cgi" name=form2 method="post">
  <input type="hidden" name="action" value="subscribe">
  <input type="button" name="goForm2" value="submit" onClick="submitThis('inner');">


-Allan
0
 
LVL 5

Expert Comment

by:ho_alan
ID: 9776463
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 3

Accepted Solution

by:
monvelasquez earned 155 total points
ID: 9776874
so you're saying that the small form is WITHIN the bigger form?
in that case, the action of the smaller form overrides that of the larger form.

you should not put another form inside a form (i.e. nesting)...
you should separate your forms...
0
 
LVL 11

Expert Comment

by:Zontar
ID: 9777426
> in that case, the action of the smaller form overrides that of the larger form.

Ummm....... No.

In that case the behaviour is undefined, because forms cannot contain other forms. Period.

Check the HTML spec:

  <!ELEMENT FORM - - (%block;|SCRIPT)+ -(FORM) -- interactive form -->

(Translation for those of you who don't speak DTD: "FORM may contain block elements and/or SCRIPT blocks. It may not contain other FORM elements.")

So it's not a case of "should not nest", it's a case of "MUST not nest".
0
 
LVL 2

Expert Comment

by:incongruent
ID: 9777738
Well you heard it from Zontar,

you can't do that.


But if your problem exists because you need your 'outer' form spanning most of the page,  you could probably split it into multiple forms and collect them into then submit the merged one.  

I just tested this script and it seems to work by adding all the elements to the first form tag.  This may 'ugly up' your page on submit though.  



-Allan

--code as follows--

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script>
function makeAndSubmitTheBigForm()
{
//form[0] will be the big form....


//countAllElements
var elementCounter=0;

  //start at form[1] and add all elements to form[0]
  for ( var loop1=1; loop1 < document.forms.length; loop1 ++)
  {
      for ( var loop2=0; loop2 < document.forms[loop1].elements.length; loop2 ++)
          {
                 //increment element counter
                 elementCounter++;

                 //add the element to form[0]
                 document.forms[0].appendChild(document.forms[loop1].elements[loop2]);
               }
   }
 
  document.forms[0].submit();

}</script>
</HEAD>

<BODY>
<form action="none" method="get">
</form>

<form name=1>
<input type=text name=abc value="WOW">
</form>
<form name=2>
<input type=text name=def value="WOW">
</form>
<form name=3>
<input type=text name=ghi value="WOW">
</form>

<input type=button name=click value=click onclick="makeAndSubmitTheBigForm();">

</BODY>
</HTML>
0
 
LVL 11

Expert Comment

by:Zontar
ID: 9779187
Another possibility might be the creative use of CSS positioning.

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now