Jump to content

[SOLVED] Validating form markup


alex3

Recommended Posts

Hi,

 

I've got this code for a form

 

<form action="blank.php" method="get">
<label for="username">Username:</label><br>
<input id="username" type="text"><br>
<label for="password">Password:</label><br>
<input id="password" type="password">
<input id="submit" type="submit" value="Submit">
</form>

 

And the W3C validator tells me it's invalid. It's main complaint is that

"document type does not allow element "label"/"br"/"input" here;  missing one of "P", "H1", "H2", "H3", "H4", "H5", "H6", "PRE", "DIV", "ADDRESS" start-tag".

It also tells me that

end tag for "FORM" which is not finished

 

I can't see a problem, sites usually teach this sort of form formatting; should I actually be wrapping every element inside <p> tags or something? <form> is a block level element so I'm a bit lost as to what to do.

 

Cheers

Link to comment
https://forums.phpfreaks.com/topic/165975-solved-validating-form-markup/
Share on other sites

You have to wrap all the elements inside the <form> tags with one more more divs in strict doctypes. That will get rid of your second error as well.

 

Do you mean wrap the entire form in a div (which it is) or wrap every component of the form in a div? Like:

 

<div>
<form>
<div><label></div>
<div>input</div>
</form>
</div>

 

Because that just seems nonsensical to me. Unless you mean something like

 

<div>
<form>
<div>
<label>
<input>
</div>
</form>
</div>

I have the entire form in a div as the form appears in it's own 'window' when called.

 

I put everything inside the <form></form> in to one div (the second option in my previous post) and now the errors (all nine of them!) have disappeared.

 

Thanks very much for the help!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.