multiple forms on 1 page

websss
websss used Ask the Experts™
on
Hi

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 asp.net doesn't allow multiple forms

whats a quick easy way to do this?
<form name="form2" id="form2" method="post" action="http://clients.mysender.com/form.php?form=5" target="_blank" >

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

</form>

Open in new window

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

Example:




<html>
<body>

<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"/>
</form>

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

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

</body>
</html>

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.

websssCEO

Author

Commented:
can i put my non-runatserver form inside the standard runatserver asp.net form?
websssCEO

Author

Commented:
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:

Option1

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>
</form>

New situation:

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

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="test@test.com" id="txtEmail" />
<input type="button" value="Go" id="submitBtn" name="submitBtn" onClick="window.open('http://clients.mysender.com/form.php?form=5&amp;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