0

Can someone tell me why the W3C Validation Service says that this code is not valid?

<!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" xml:lang="en" lang="en"> <head> <title>this is the title of the web page</title> </head> <body> <form action="formscript.php" method="post"> first name:<input type="text" name="firstname" /> <input type="submit" /> </form> </body> </html> 
1
  • 1
    Can you update your question and put what error is the validator giving you? Commented Oct 2, 2012 at 13:39

2 Answers 2

1

I tried both codes and the validator says that the question code is valid as XHTML 1.0 Transitional.

Anyway, the problem here is that you have no <fieldset> inside your <form> and that the text <input> has no <label>.

<form action="formscript.php" method="post" name="thisform"> <fieldset> <label for="firstname">first name:</label> <input type="text" name="firstname" /> <input type="submit" /> </fieldset> </form> 

And don't forget the DOCTYPE.

Sign up to request clarification or add additional context in comments.

1 Comment

The label element, though useful, has nothing to do with the validation issue. And fieldset is just one of the possible block-level wrappers. If used, it requires a `legend' subelement. There are also other markup errors in your proposed solution (some of which did not exist in the original), as you can see by trying to validate your code.
0

The markup, as originally posted, makes a valid XHTML 1.0 Transitional document if the XHTML 1.0 Transitional document type declaration is added at the start.

As edited by @adamjansch, with the XHTML 1.0 Strict document type declaration, it is not valid, and presumably it was validated using that document type declaration. Then the first error message is “character data is not allowed here” with some explanations of possible causes, including “putting text directly in the body of the document without wrapping it in a container element (such as a <p>aragraph</p>)”. This gets close: the problem is that in XHTML 1.0 Strict, a form element may have block-level children only.

This means that any text and text-level markup like input must be wrapped in one or more block containers, such as p, div, fieldset, or table. Of these, div is the only neutral one, with no default impact on rendering:

<!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" xml:lang="en" lang="en"> <head> <title>this is the title of the web page</title> </head> <body> <form action="formscript.php" method="post"> <div> first name:<input type="text" name="firstname" /> <input type="submit" /> </div> </form> </body> </html> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.