validator: <input> as a child of <form>

M

Mitja

I need some help to get a thing straight: why doesn't W3C's validator allow
the <input> element as a direct descendant of <form>?

An example of it can be seen at
http://www.oktaeder.com/?page=g_single&game=444 (search for "hidden" in
source), and here are the validation results:
http://validator.w3.org/check?uri=http://www.oktaeder.com/?page=g_single&game=444

The error I get is ''document type does not allow element "INPUT" here;
missing one of "P", "H1", "H2", "H3", "H4", "H5", "H6", "PRE", "DIV",
"ADDRESS" start-tag''. This seems clear enough, and sure thing, if I change
<div><form><input> to <div><form><p><input>, it validates. What is bugging
me is that I don't understand this behavior. I don't doubt it's specified
somewhere, but can't find it.

http://www.w3.org/TR/1999/REC-html401-19991224/interact/forms.html#h-17.4
doesn't seem to mention anything in that direction. HtmlHelp, which is more
comprehensible if not as official, explicitly says that <input> may be
contained in any block-level element, which <form> is. Any hints?

Mitja
 
S

Steve Pugh

Mitja said:
I need some help to get a thing straight: why doesn't W3C's validator allow
the <input> element as a direct descendant of <form>?

Because it's not allowed under the rules of certain versions of
(X)HTML.
http://www.w3.org/TR/1999/REC-html401-19991224/interact/forms.html#h-17.4
doesn't seem to mention anything in that direction. HtmlHelp, which is more
comprehensible if not as official, explicitly says that <input> may be
contained in any block-level element, which <form> is. Any hints?

To see where elements are allowed look at the rules for the containing
element, not the contained element. Hence:
http://www.w3.org/TR/html401/interact/forms.html#h-17.3
Where you see that forms can contains (%block;|SCRIPT)+ which means
they can contain one or more block level or script elements. input is,
as you say, an inline element and hence is not allowed.

If you want to write Strict HTML 4.01 (or Strict XHTML 1, or XHTML
1.1, or ISO-HTML) then you need to wrap all you input elements inside
a block level element.

Steve
 
B

brucie

in post: <
Mitja said:
I need some help to get a thing straight: why doesn't W3C's validator allow
the <input> element as a direct descendant of <form>?

it does depending on dtd (i'm using html4.01 here).

under the strict dtd a form says it likes fun giggly block elements
(%block):

<!ELEMENT FORM - - (%block;|SCRIPT)+ -(FORM) -- interactive form -->

block element:

<!ENTITY % block "P | %heading; | %list; | %preformatted; | DL | DIV | NOSCRIPT | BLOCKQUOTE | FORM | HR | TABLE | FIELDSET | ADDRESS">

so you get an error if you have inline elements in the <form>

but under the loose dtd is says it also likes fun giggly inline elements
(%flow):

<!ELEMENT FORM - - (%flow;)* -(FORM) -- interactive form -->

%flow being:

<!ENTITY % flow "%block; | %inline;">

the above means either inline or block elements. we already know what
block elements are so we have a look at what inline elements are. it
says:

<!ENTITY % inline "#PCDATA | %fontstyle; | %phrase; | %special; | %formctrl;">

at the end it says '%formctrl' (form controls) so if we look that up it
says:

<!ENTITY % formctrl "INPUT | SELECT | TEXTAREA | LABEL | BUTTON">

so our <form> with a loose dtd can have those inline form elements
without any problems (and just about anything else you cant think of
throwing inside the said:
Any hints?

no
 
D

David Dorward

Mitja said:
I need some help to get a thing straight: why doesn't W3C's validator
allow the <input> element as a direct descendant of <form>?

The content model of <form> is the same as <body>, you can only put block
level elements inside it. Examples include <table>, <div> and <fieldset>.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,433
Messages
2,571,683
Members
48,796
Latest member
Greg L.

Latest Threads

Top