Jump to content

Form element


coolpro

Recommended Posts

HTML 4.01 and XHTML Strict requieres, that form element contains block-level elements.

This would be incorrect:

<form>
<input></input>
</form>

 

The correct one is:

 

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

 

But I don't understand why.

Link to comment
Share on other sites

http://htmlhelp.com/reference/html40/forms/form.html

 

It is true, because when I use:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<div>
<form action="index.php">

<input type="text" id="field1" name="field1" />

</form>
</div>
</body>
</html>

 

W3C validator show error:

 

Line 12, Column 46: document type does not allow element "input" here; missing one of "p", "h1", "h2", "h3", "h4", "h5", "h6", "div", "pre", "address", "fieldset", "ins", "del" start-tag.

 

and when:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<div>
<form action="index.php">
<div>
<input type="text" id="field1" name="field1" />
</div>
</form>
</div>
</body>
</html>

 

then: This Page Is Valid XHTML 1.0 Strict!

Link to comment
Share on other sites

Oh yea that... I was confused I don't exactly know why it is that way I just put my form one div under the inputs... its fits in perfectly with the rest of the code and I don't get errors...

 

I would do:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form action="index.php">
<div>
<input type="text" id="field1" name="field1" />
</div>
</form>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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