I just have a question about putting a single form with multiple inputs into different divs.
I have 4 main sections that I need to divide into separate divs but they all must get posted to a single php file. The separation is needed as I am trying to set the layout of the page.
<div id="1">
<form method="post" action="process.php">
URL <input type="text" name="url" size="50"/>
</div>
<div id="2">
<input type="checkbox" name="ck1" value="option1" />
<input type="checkbox" name="ck2" value="option2" />
<input type="checkbox" name="ck3" value="option3" />
</div>
<div id="3">
<input type="checkbox" name="ck4" value="option4" />
<input type="checkbox" name="ck5" value="option5" />
<input type="checkbox" name="ck6" value="option6" />
</div>
<div id="4">
<input type="submit" value="Submit">
</form>
</div>
This does work but does not validate for obvious reason. I tried using the fieldset element but it has that line border around the filesets just dosen't seem to be suitable for my situation. What would be the proper way of formmating this and have it still work?
The div tag is known as Division tag. The div tag is used in HTML to make divisions of content in the web page like (text, images, header, footer, navigation bar, etc). Div tag has both open(<div>) and closing (</div>) tag and it is mandatory to close the tag.
It is totally fine . The form will submit only its input type controls ( *also Textarea , Select , etc...). You have nothing to worry about a div within a form .
What you need to do is use fieldset tag, however, as always this is one option of many.
To illustrate this example, see my code/result here: http://jsfiddle.net/grARw/
Make sure that the form tags are at the top and bottom and not in between div elements.
Here's the code:
<form method="post" action="process.php">
<fieldset id="f1">
<label>URL</label><input type="text" name="url" size="50"/>
</fieldset>
<fieldset id="f2">
<p><input type="checkbox" name="ck1" value="option1" /> Yes</p>
<p><input type="checkbox" name="ck2" value="option2" /> No</p>
<p><input type="checkbox" name="ck3" value="option3" /> Maybe</p>
</fieldset>
<fieldset id="f3">
<input type="checkbox" name="ck4" value="option4" /> Great
<input type="checkbox" name="ck5" value="option5" /> Average
<input type="checkbox" name="ck6" value="option6" /> Poor
</fieldset >
<fieldset id="f4">
<input type="submit" value="Submit">
</fieldset>
</form>
The semantic way to do this is with the <fieldset>
tag.
http://www.w3schools.com/TAGS/tag_fieldset.asp
Also, this is a big reason your code doesn't validate:
</form>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With