Page 1 of 1
Valid inputs
Posted: Tue Dec 19, 2006 9:03 am
by shiznatix
I am trying to make everything 100% valid XHTML. The only real problem I am coming across is this:
Code: Select all
<form action="asdsdf.php" method="post">
<input type="submit" value="Submit" />
</form>
That is NOT valid XHTML strict. It says I cant put a input there. If I do this:
Code: Select all
<form action="asdsdf.php" method="post">
<div style="display: inline;">
<input type="submit" value="Submit" />
</div>
</form>
Then it is valid. Now do I really have to go around and put a div tag everywhere I want to have an input type to make it valid? Seams silly to me and does not make sence to me why the first is not valid.
If someone could shed some light that would be fantastic.
Posted: Tue Dec 19, 2006 11:06 am
by GeertDD
You don't need divs. I'd use a p tag to put around the input. Note that if you want your inputs lined up horizontally, you can just put them after each other inside the p (or div) tag. No need for display:inline tricks.
Posted: Tue Dec 19, 2006 11:12 am
by matthijs
And/or use a label.
Posted: Tue Dec 19, 2006 11:51 am
by shiznatix
aye but I have to put them in something? I dont see why a input type hidden should have to be inside a p or a div or anything other than a form. Seams silly. Sigh, ill do it though.
Posted: Tue Dec 19, 2006 12:42 pm
by Kieran Huggins
In XHTML a <form> is not a layout component, although it does change the layout somewhat in most browsers. Grr.
You should
almost always wrap inputs in labels like so:
Code: Select all
<label>Name: <input name="name" type="text"/></label>
As for hidden fields, you could either wrap them in hidden divs or just be a rebel and fail validation.
It feels good to validate, but it feels even better to know why you don't need to!
Cheers,
Kieran
Posted: Tue Dec 19, 2006 1:56 pm
by GeertDD
Kieran Huggins wrote:In XHTML a <form> is not a layout component, although it does change the layout somewhat in most browsers. Grr.
Right. Setting margin and padding to zero helps a lot though.
You should
almost always wrap inputs in labels like so:
Code: Select all
<label>Name: <input name="name" type="text"/></label>
Or like this:
Code: Select all
<p><label for="name">Name:</label> <input id="name" name="name" type="text"/></p>
It feels good to validate, but it feels even better to know why you don't need to!
Sure. Validation doesn't mean everything. It is perfectly possible to create a valid xhtml 1.0 mess.