DWilliams Posted August 5, 2010 Share Posted August 5, 2010 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? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted August 5, 2010 Share Posted August 5, 2010 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 Quote Link to comment Share on other sites More sharing options...
haku Posted August 5, 2010 Share Posted August 5, 2010 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. Quote Link to comment Share on other sites More sharing options...
DWilliams Posted August 5, 2010 Author Share Posted August 5, 2010 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... Quote Link to comment Share on other sites More sharing options...
haku Posted August 7, 2010 Share Posted August 7, 2010 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. Quote Link to comment Share on other sites More sharing options...
phpnewbei Posted September 18, 2010 Share Posted September 18, 2010 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.