Why will my HTML not validate ? - <FORM>

liunx

Guest
Here is a link to my webpage.....<br />
My Webpage (<!-- m --><a class="postlink" href="http://roundthebend.greater-peterborough.com/new/index.php">http://roundthebend.greater-peterboroug ... /index.php</a><!-- m -->)<br />
<br />
I am trying to validate this HTML 4.01 Strict, but I get errors within a <FORM> tag. It says that the <INPUT> elements are not allowed unless I have a <P>, <H1> etc, <PRE>, <DIV> or <ADDRESS> tag.<br />
<br />
Well the form is within a <DIV>, but am I missing something else ?<br />
<br />
Thanks<!--content-->Could we please see the exact code you're working with? Or better yet, a link to the page you're having trouble with?<!--content-->at the top of my original post is a link to the page....but here's the HTML anyway.<br />
<br />
<br />
<DIV ID='dynamicmenu'><br />
<FORM METHOD=POST ACTION='login.php'><input type="hidden" name="PHPSESSID" value="46e8c97ffb9ba0f795e9cde6489fcfc7" /><br />
Username:<INPUT CLASS='Login' TYPE=TEXT SIZE=8 MAXLENGTH=8 NAME='Username'><br />
Password:<INPUT CLASS='Login' TYPE=PASSWORD SIZE=8 MAXLENGTH=8 NAME='Password'><br />
<INPUT CLASS='Login' TYPE=SUBMIT NAME='Login' VALUE='Login'><br />
</FORM><br />
</DIV><!--content-->Damn, sorry about that. There's proof I'm tired... Or maybe just blind. :D<br />
<br />
Anyway, try this:<form method="post" action="login.php"><br />
<div id="dynamicmenu"><br />
<input type="hidden" name="PHPSESSID" value="46e8c97ffb9ba0f795e9cde6489fcfc7"><br />
<label for="user"><br />
Username:<br />
</label><br />
<input class="Login" type="text" size="8" maxlength="8" name="Username"><br />
<br />
<label for="pass"><br />
Password:<br />
</label><br />
<input class="Login" type="password" size="8" maxlength="8" name="Password"><br />
<input class="Login" type="submit" name="Login" value="Login"><br />
</div><br />
</form><!--content-->It's gone midnight here, so I can understand if you're tired. I appreciate your assistance.<br />
<br />
However, it doesn't like the <LABEL> tag now, it gives the same error as it did for <INPUT> and it still has the errors for <INPUT><!--content-->You're quite welcome. It doesn't like the <label> tags, huh? I find that rather weird as I'm almost sure it is in the HTML 4.01 Strict DOCTYPE. However, you can omit them. It's just a habit (a good habit, actually) I have of adding them when I was correcting your code. I also tried closing your <input> tags as well since I'm so used to coding XHTML. By having the <div> inside of the <form> tag, but wrapping around it's child elements should have worked correctly, although there could possibly be something else causing your validation errors.<!--content-->I've never been able to find what I want on the W3 website, but I suppose today was the day I learned to look properly.<br />
<br />
Within a <FORM> tag you must have a <DIV> or <P> or similar before any other tags. I failed to notice in your example that the <DIV> tags were inside the <FORM> so that should fix it. However, because I am using PHP Sessions, my host must use some code to insert the Session ID as a hidden element in all forms. It's impossible for me to put anything before it, it seems to know exactly when my <FORM> tag ends before adding that HIDDEN field.<br />
<br />
EDIT: Here's an example from the W3 specifications:<br />
<br />
<FORM action="http://somesite.com/prog/adduser" method="post"><br />
<P><br />
<LABEL for="firstname">First name: </LABEL><br />
<INPUT type="text" id="firstname"><BR><br />
<LABEL for="lastname">Last name: </LABEL><br />
<INPUT type="text" id="lastname"><BR><br />
<LABEL for="email">email: </LABEL><br />
<INPUT type="text" id="email"><BR><br />
<INPUT type="radio" name="sex" value="Male"> Male<BR><br />
<INPUT type="radio" name="sex" value="Female"> Female<BR><br />
<INPUT type="submit" value="Send"> <INPUT type="reset"><br />
</P><br />
</FORM><br />
<br />
<br />
<br />
In fact, now that I've put the <DIV> inside my <FORM> it actually solved another problem I was having to do with the size of the <DIV>.<br />
<br />
Many Thanks, you've been a great help.<!--content-->You're very welcome. It can be rather confusing sometimes when you first start to care about the validity of your code, but you'll catch on quickly. The trick here is that all contents of the form must be encased by a block-level element (even though I believe <form> is a block-level element, but I suppose there are reasons behind this). I'd also recommend that once you feel comfortable with HTML 4.01 Strict and valid code, that you move onto XHTML 1.0 Transitional and then work your way up to XHTML 1.0 Strict.<!--content-->
 
Back
Top