views:

2610

answers:

6

Any ideas why this won't validate here:

http://validator.w3.org/#validate_by_input

It seems the form input tags are wrong but reading through the XHTML spec they should validate fine. Any ideas?

<!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"&gt;
 <head>
  <title>Test</title>
 </head>

 <body>
    <div class="Header">
     <table class="HeaderTable">
      <tr>
       <td>
        <div class="Heading">Test <span class="Standard">Test</span>
        </div>
       </td>
       <td>
        <div class="Controls">
         <form id="ControlForm" method="get" action="Edit.php">
          <input type="submit" name="action" id="Edit" value="Edit" />
          <input type="submit" name="action" id="New" value="New" />
         </form>
        </div>
       </td>
      </tr>
     </table>
    </div>
 </body>
</html>
+2  A: 

Try putting a fieldset tag around the inputs. I think the idea of forms in XHTML is that they can't have direct descendants that aren't div, fieldset, etc.

Rahul
+2  A: 

As someone else put it:

[quote] The validator is telling you that your hidden input element cannot immediately follow the form tag - it needs to have a container element of some kind. [/quote]

(Source)

I guess a fieldset could help; See The XHTML DTD:

<!ELEMENT form %form.content;>

<!ENTITY % form.content "(%block; | %misc;)*">

<!ENTITY % misc "noscript | %misc.inline;">
<!ENTITY % misc.inline "ins | del | script">

<!ENTITY % block "p | %heading; | div | %lists; | %blocktext; | fieldset | table">

<!ENTITY % heading "h1|h2|h3|h4|h5|h6">
<!ENTITY % lists "ul | ol | dl">
<!ENTITY % blocktext "pre | hr | blockquote | address">

No input for you :(

FOR
Thanks, you're right, the inputs need to be inside a container of sort sort.
Gary Willoughby
+2  A: 

You need to move

<div class="Controls">

so that it's inside the <form tag


This validates nicely

<!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"&gt;
<head>
    <title>Test</title>
</head>

<body>
    <div class="Header">
        <table class="HeaderTable">
        <tr>
            <td>
                <div class="Heading">Test <span class="Standard">Test</span></div>
            </td>
            <td>
                <form id="ControlForm" method="get" action="Edit.php">
                    <div class="Controls">
                        <input type="submit" name="action" id="Edit" value="Edit" />
                        <input type="submit" name="action" id="New" value="New" />
                    </div>
                </form>
            </td>
        </tr>
        </table>
    </div>
</body>
</html>
Mark Biek
I always use a <fieldset> inside every form now to avoid this problem.
Gary Willoughby
A: 
<!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"&gt;
 <head>
  <title>Test</title>
 </head>

 <body>
    <div class="Header">
        <table class="HeaderTable">
                <tr>
                        <td>
                                <div class="Heading">Test <span class="Standard">Test</span>
                                </div>
                        </td>
                        <td>

                            <form id="ControlForm" method="get" action="Edit.php">
                                <div class="Controls">
                                                <input type="submit" name="action" id="Edit" value="Edit" />
                                                <input type="submit" name="action" id="New" value="New" />
                                </div>
                            </form>

                        </td>
                </tr>
        </table>
    </div>
 </body>
</html>

Put your div inside your form.

François
A: 

Your input elements should be within a fieldset. This validates and has the added benefit of making the document more accessible to non-visual user agents.

As an aside, your markup is suffering from divitis a bit. You could put classes on the table cells directly rather than nesting div elements within them (I'm not going to comment on the use of tables for layout). Also, you could style the form element directly rather than nesting it within a div.

Anyway, here's your example with a fieldset added so it validates:

<!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"&gt;
  <head>
    <title>Test</title>
  </head>
  <body>
    <div class="Header">
      <table class="HeaderTable">
        <tr>
          <td>
            <div class="Heading">Test <span class="Standard">Test</span></div>
          </td>
          <td>
            <div class="Controls">
              <form id="ControlForm" method="get" action="Edit.php">
                <fieldset>
                  <input type="submit" name="action" id="Edit" value="Edit" />
                  <input type="submit" name="action" id="New" value="New" />
                </fieldset>
              </form>
            </div>
          </td>
        </tr>
      </table>
    </div>
  </body>
</html>
John Topley
A: 

I had the very same problem and it took me some time to figure out. Is this a recent change with the w3c validator? it's just I'm sure some of my pages with forms validated in the past, but now they all seem to through up errors for the same problem.

I used to always do something like:

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

and get validation errors, so now I just add fieldset or div around all the labels and inputs to get it to validate, like this:

<div>
<form>
    <fieldset>or<div>
        <label></label>
        <input />
        <label></label>
        <input />
        <label></label>
        <input />
    </fieldset>or</div>
</form>

Seems to work, but I'm sure I didn't have to do this in the past... hmmm?

Adrian