multiple forms on 1 page

websss used Ask the Experts™

i have a cms and i've been asked to create an email sign up form

the people have given me the code to integrate into their PHP system
the code they gave me is standard HTML which posts to a URL
1 parameter is on the querystring and the other 2 parameter are used on the "post" so they are not contained within the querystring

however, i dont think its as simple as that as doesn't allow multiple forms

whats a quick easy way to do this?
<form name="form2" id="form2" method="post" action="" target="_blank" >

    <input type="hidden" id="format" name="format" value="h" />
    <input type="text" name="email" value=""   id="txtEmail"  class="emailSignUp"  />
    <input type="submit" id="submitBtn" name="submitBtn"   class="emailSignUpButton"   />


Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
ASP.NET does allow multiple forms on one page, but you cant nest them.
Forms give you the opportunity to group fields and post only the neccesary data to the attached URL.



<p>Sign in</p>

<form id="form1" action="login.asp" method="post">
  <input type="text" name="user" />
  <input type="password" name="password" />
  <input type="submit"/>

<p> or sign up for our newsletter</p>

<form id="form2" action="newsletter.asp" method="post">
  <input type="text" name="email" />
  <input type="submit"/>


Open in new window

Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Ah, forgot about the "one form with runat=server per page" rule...

You can only have several forms on your page, but only one form with "runat=server". Because your second form only uses static data, this should be no problem.



can i put my non-runatserver form inside the standard runatserver form?


ok slight issue
as its in a cms the whole server form needs to be throughout the page so i cant have multiple forms

what other options do i have
With a little luck you have 2 options i can think of:


If you change your example code to start with </form> you close the main form and can use the existing </form> to close your form. This only works if in the remaining html there are no variables or buttons that are associated with the main form.

Current situation:

<form id="main">
   <form id="email"></form>

New situation:

<form id="main">
<form id="email">

Option 2
Don't use a form, but use Javascript and the OnClick event of the email send button to change the action of the main form. That way you can use 1 form for 2 actions. However this will not work if there are duplicate variable names.

Hope this helps...

2) Dont use a second form, but change the action / fields on the main form on the main form use javascript to on the email button to
<form id="main"">
  <form id="email"
  </form> <!-- /email -->
</form> <-- /main -->

Open in new window

And a 3rd option. This may not work if the server only accpets the "post" action:

<input type="text" name="email" value="" id="txtEmail" />
<input type="button" value="Go" id="submitBtn" name="submitBtn" onClick="';format=h&amp;email=' + document.getElementById('txtEmail').value );" />

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial