tags:

views:

1031

answers:

6
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>A webpage</title>
</head>
<body>
  <p>
  <form action="something.php" method="get">
    <input type="submit" value="Hello"/>
  </form>
</p>
</body>
</html>
+1  A: 

According to this, because:

Line 8, Column 44: document type does not allow element "form" here; missing one of "object", "ins", "del", "map" start-tag ✉ The mentioned element is not allowed to appear in the context in which you've placed it; the other mentioned elements are the only ones that are both allowed there and can contain the element mentioned. This might mean that you need a containing element, or possibly that you've forgotten to close a previous element.

One possible cause for this message is that you have attempted to put a block-level element (such as "p" or "table") inside an inline element (such as "a", "span", or "font").

Line 9, Column 40: 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 input type="submit" value="Hello" The mentioned element is not allowed to appear in the context in which you've placed it; the other mentioned elements are the only ones that are both allowed there and can contain the element mentioned. This might mean that you need a containing element, or possibly that you've forgotten to close a previous element.

One possible cause for this message is that you have attempted to put a block-level element (such as "p" or "table") inside an inline element (such as "a", "span", or "font").

jeffamaphone
+1 for the following: "... you have attempted to put a block-level element (such as "p" or "table") inside an inline element (such as "a", "span", or "font")."
fiXedd
+1  A: 

You can't nest a <form> inside a <p>.

The W3C validator can point out these errors for you.

mipadi
So the question is "Why can't you do X?" and you answer "because you can't do X". Yeah, that's helpful.
fiXedd
The question was "Why doesn’t form nested in p validate as XHTML?" The answer is, "Because you can't." What more do you want? A solution? The solution is pretty simple: don't put the <form> inside the <p> tag.
mipadi
Or rather the answer is, "Because it's invalid XHTML," which is basically the same as, "You can't do that."
mipadi
+1  A: 

You can't put form inside paragraph. Write like this:

<body>
  <form action="something.php" method="get">
  <p>
    <input type="submit" value="Hello"/>
  </p>
  </form>
</body>
Artyom
He asked _WHY_ it doesn't validate, not how to fix it.
fiXedd
A: 

Try using the W3C Markup Validator, which will tell your what is invalid with most (X)HTML and CSS documents.

Dave Rigby
I think he probably realizes this since he already knows it isn't validating. He was asking why it was invalid, not whether.
fiXedd
Well seeing as the W3C validator explains pretty well why it's invalid, I figured that was the most informative way to solve the problem. It's better to tell someone how to solve a problem, rather than just give them the answer.
Dave Rigby
+11  A: 

Look at the error messages that you get when you try that with http://validator.w3.org

Apart from a warning that you haven't specified a character encoding (and that it's therefore assuming UTF-8), the main error is that a <p> isn't allowed to contain non-inline content. You can either remove the <p> and </p> completely, or, move them inside the <form>.

As for 'why', it's because that's how it's defined in the schema which defines what is and what is not valid XHTML. If you look at this section of the XHTML definition you'll see that <p> is only allowed to contain text or 'inline' (not 'block') tags. However a <form> counts as 'block' content not as 'inline' content.

In other words, a form can contain paragraphs, but a paragraph cannot contain forms.

ChrisW
+1 for being the only answer (so far) to actually explain what the problem is
Tyler McHenry
+1 for the same reason here too. Everyone else is just like "yeah, it doesn't validate according to validator.w3c.org
fiXedd
A: 

I ran a test with your HTML code through validator.w3.org and the result is that you need to swap the P and FORM tags for it to pass as valid W3C HTML.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>A webpage</title>
</head>
<body>
  <form action="something.php" method="get">
    <p>
      <input type="submit" value="Hello"/>
    </p>
  </form>
</body>
</html>
Michiel
He asked _WHY_ it doesn't validate, not how to fix it.
fiXedd