Jump to content

Multiple forms with one submit button


DWilliams

Recommended Posts

I'm making a settings page. The settings are divided into groups with other page content in-between. I want to have one single "save" button on the bottom that submits my form.

 

Now, I know it's not technically valid HTML to just open a form tag at the top of my page, output all my content, then close it at the bottom. I was hoping that giving them all the same name would do it but apparently not. This is what I tried:

 

<form name="test" method="get">
<input type="text" name="test1" />
</form>
blah 
blah
blah
content here
<form name="test" method="get">
<input type="text" name="test2" />
<input type="submit" />
</form>

 

When the form is submitted, only values in the same form tag as the submit button get sent, so in this example test2 gets submitted but not test1

 

How should I design this?

Link to comment
Share on other sites

I'm not aware of any reason you can't open the form tag at the beginning and close it at the end of the page. Its' just a container for the form elements and controls. If you have any doubts, you can always set up a script that way and see if it fails validation because of the <form> tags at http://validator.W3.org

Link to comment
Share on other sites

I'm making a settings page. The settings are divided into groups with other page content in-between. I want to have one single "save" button on the bottom that submits my form.

 

Now, I know it's not technically valid HTML to just open a form tag at the top of my page, output all my content, then close it at the bottom. I was hoping that giving them all the same name would do it but apparently not. This is what I tried:

 

<form name="test" method="get">
<input type="text" name="test1" />
</form>
blah 
blah
blah
content here
<form name="test" method="get">
<input type="text" name="test2" />
<input type="submit" />
</form>

 

When the form is submitted, only values in the same form tag as the submit button get sent, so in this example test2 gets submitted but not test1

 

How should I design this?

 

Open your form element at the start of the top form, close it at the bottom of the last form. No problems with that as long as you don't have overlapping tags.

Link to comment
Share on other sites

I'm not aware of any reason you can't open the form tag at the beginning and close it at the end of the page. Its' just a container for the form elements and controls. If you have any doubts, you can always set up a script that way and see if it fails validation because of the <form> tags at http://validator.W3.org

 

Well from a functional standpoint the browsers render it correctly, but as I recall from doing this in the past, it won't validate like that. It seems to complain about this or that tag not being allowed inside a form. Maybe I'm just remembering wrong...

Link to comment
Share on other sites

It depends exactly what you are putting there. if you are putting your head, body, or HTML tags in there, then yes, you will run into some errors. But if you keep it fully enclosed in the body, I think you won't run into any problems.

Link to comment
Share on other sites

  • 1 month later...

I'm making a settings page. The settings are divided into groups with other page content in-between. I want to have one single "save" button on the bottom that submits my form.

 

Now, I know it's not technically valid HTML to just open a form tag at the top of my page, output all my content, then close it at the bottom. I was hoping that giving them all the same name would do it but apparently not. This is what I tried:

 

<form name="test" method="get">
<input type="text" name="test1" />
</form>
blah 
blah
blah
content here
<form name="test" method="get">
<input type="text" name="test2" />
<input type="submit" />
</form>

 

When the form is submitted, only values in the same form tag as the submit button get sent, so in this example test2 gets submitted but not test1

 

How should I design this?

The submit button doesn't have any contact with test1 since you end your form tag after test1 and create a new tag with a button, try this instead

I'm making a settings page. The settings are divided into groups with other page content in-between. I want to have one single "save" button on the bottom that submits my form.

 

Now, I know it's not technically valid HTML to just open a form tag at the top of my page, output all my content, then close it at the bottom. I was hoping that giving them all the same name would do it but apparently not. This is what I tried:

 

<form name="test" method="get">
<input type="text" name="test1" />
blah 
blah
blah
content here
<input type="text" name="test2" />
<input type="submit" />
</form>

Then when you press submit both test1 and test2 will be sended!

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.