We help IT Professionals succeed at work.

Can forms be nested on a page?

edmac
edmac asked
on
I have a web page with multiple forms. I would like to email the complete page when it is finished.. Can the forms be nested within a form to submit the email?
Comment
Watch Question

Top Expert 2013

Commented:
No.

You can have more than one form on the page but they cannot be nested.  The solution is
put hidden fields on the first form.  When the second form is completed the fields get moved
to the hidden forms on the first form and are submitted with it.

Cd&

Commented:
And define 'email the complete page'

It's better NOT to try to create an HTML email. It's much easier to create a neatly formatted regular email that everybody can read, and add a link to a web page if you feel it necessary.

If what you're generating is an order, or an order confirmation, HTML formatting really isn't necessary anyway.

Author

Commented:
How are the hidden fields updated from the other forms?
updating the hidden fields ?
you can do it in many ways
say you have a text txt1 whose value is to be copied to a hidden field hid1
for this you can use event like onchange of the text , so every time the text changes , the new change is copied to the corresponding hidden field
eg.
write this on the onchange event of the text field txt1
window.document.all.hid1.value = window.document.all.txt1.value

or if you have a submit button then
on the onsubmit event you can write such multiple value assignments to copy the values of more then one HTML controls/fields to their corresponding hidden fields

Top Expert 2013
Commented:
sorry edmac, I didn't see your last comment, it must have been during the tch problems on the site.

Okay hidden field population.
In the first form let's say you have:

<form name="form1" action="JavaScript:passValues()">
  <input type="text" name="text1">
  <input type="text" name="text2">
  <input type="submit">
</form>

In the second form:

<form name="form2" action="script.cgi">
<input type="hidden" name="text1">
<input type="hidden" name="text2">
  then all the other fields
<input type="submit">
</form>

The submit on the first form will transfer the field values usng a script which goes in the head like this:

<script language="JavaScript">
<!--
   function passValues()
   {
      document.form2.text1.value=document.form1.text1.value;
document.form2.text2.value=document.form1.text2.value;
}
//-->
</script>



Cd&
Top Expert 2013

Commented:
Glad I could help. Thanks for the A. :^)

Cd&

Explore More ContentExplore courses, solutions, and other research materials related to this topic.