By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,785 Members | 1,079 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,785 IT Pros & Developers. It's quick & easy.

INPUT element not allowed in form, can't find my error

P: n/a
http://oakroadsystems.com/nonce/zonk.htm (12 lines)
http://validator.w3.org/check?charse....htm&outline=x


The W3C validator says "INPUT is not allowed here". I'm sure my
mistake is really obvious, but I just can't see it. I'd appreciate
another pair of eyes pointing out the problem.

For convenience, here's the entire file. I've stripped it down to
the essentials, still get the message, and still can't see what I'm
missing:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en-US"><head>
<title>How to Convert Units of Measurement</title>
</head>
<body>
<form action="http://www.google.com/search" method="get">
<input type="text" size="40" name="q" value="6145 mi in km">
<input type="submit" value="Google conversion">
</form>
</body>
</html>
--
Stan Brown, Oak Road Systems, Cortland County, New York, USA
http://OakRoadSystems.com/
HTML 4.01 spec: http://www.w3.org/TR/html401/
validator: http://validator.w3.org/
CSS 2 spec: http://www.w3.org/TR/REC-CSS2/
2.1 changes: http://www.w3.org/TR/CSS21/changes.html
validator: http://jigsaw.w3.org/css-validator/
Jul 20 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Stan Brown <th************@fastmail.fm> writes:
The W3C validator says "INPUT is not allowed here". I'm sure my
mistake is really obvious, but I just can't see it. I'd appreciate
another pair of eyes pointing out the problem.
<input> is not allowed directly inside <form> in the strict
doctype. It needs a block level element (<div> or <fieldset> would
seem best) interposed.
<form action="http://www.google.com/search" method="get">
<input type="text" size="40" name="q" value="6145 mi in km">
<input type="submit" value="Google conversion">
</form>


--
Chris
Jul 20 '05 #2

P: n/a


Stan Brown wrote:
http://oakroadsystems.com/nonce/zonk.htm (12 lines)
http://validator.w3.org/check?charse....htm&outline=x

The W3C validator says "INPUT is not allowed here".


It says more, it says

document type does not allow element "INPUT" here; missing one of "P",
"H1", "H2", "H3", "H4", "H5", "H6", "PRE", "DIV", "ADDRESS" start-tag

<input type="text" size="40" name="q" value="6145 mi in km">

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
so it tells you you need to wrap the INPUT into a container like P.
If you look at HTML 4 it defines the FORM element as
http://www.w3.org/TR/html4/interact/forms.html#h-17.3
allowing the following content
<!ELEMENT FORM - - (%block;|SCRIPT)+ -(FORM) -- interactive form -->
where block is defined as
<!ENTITY % block
"P | %heading; | %list; | %preformatted; | DL | DIV | NOSCRIPT |
BLOCKQUOTE | FORM | HR | TABLE | FIELDSET | ADDRESS">

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #3

P: n/a

"Stan Brown" <th************@fastmail.fm> wrote in message
news:MP************************@news.odyssey.net.. .
http://oakroadsystems.com/nonce/zonk.htm (12 lines)
http://validator.w3.org/check?charse....htm&outline=x
The W3C validator says "INPUT is not allowed here". I'm sure my
mistake is really obvious, but I just can't see it. I'd appreciate
another pair of eyes pointing out the problem.


Correct. I don't know why, but for strict HTML it was decided that the form
itself wouldn't directly contain its controls, that they should instead be
laid out within the form by placing them within block elements. FIELDSET is
one such block element, so this is a good incentive to use fieldsets to
group your controls on larger forms.

Jul 20 '05 #4

P: n/a
"Stan Brown" <th************@fastmail.fm> wrote in
comp.infosystems.www.authoring.html:
http://oakroadsystems.com/nonce/zonk.htm (12 lines)


(Page now removed)

Thanks to Martin Honnen and Chris Morris for your very prompt
answers, that <form> can't contain <input> but must contain some
extra block-level control which in turn contains <input>.

I had checked the 4.01 spec before posting, but I missed that. And
somehow, even though I looked at the example in 17.4.2, the "<p>"
and "</p>" didn't register on me.

Again, thanks!

--
Stan Brown, Oak Road Systems, Cortland County, New York, USA
http://OakRoadSystems.com/
HTML 4.01 spec: http://www.w3.org/TR/html401/
validator: http://validator.w3.org/
CSS 2 spec: http://www.w3.org/TR/REC-CSS2/
2.1 changes: http://www.w3.org/TR/CSS21/changes.html
validator: http://jigsaw.w3.org/css-validator/
Jul 20 '05 #5

P: n/a
On Thu, 08 Jul 2004 16:18:52 +0200, Martin Honnen <ma*******@yahoo.de>
wrote:
Stan Brown wrote:
document type does not allow element "INPUT" here; missing one of "P",
"H1", "H2", "H3", "H4", "H5", "H6", "PRE", "DIV", "ADDRESS" start-tag

<input type="text" size="40" name="q" value="6145 mi in km">

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


Odd that fieldset isn't mentioned, eh?
Jul 20 '05 #6

P: n/a


Neal wrote:
On Thu, 08 Jul 2004 16:18:52 +0200, Martin Honnen <ma*******@yahoo.de>
wrote:
Stan Brown wrote:
document type does not allow element "INPUT" here; missing one of "P",
"H1", "H2", "H3", "H4", "H5", "H6", "PRE", "DIV", "ADDRESS" start-tag

<input type="text" size="40" name="q" value="6145 mi in km">

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

Odd that fieldset isn't mentioned, eh?


Right, the validator should have listed that too.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #7

P: n/a
Martin Honnen <ma*******@yahoo.de> wrote:
document type does not allow element "INPUT" here; missing one of
"P", "H1", "H2", "H3", "H4", "H5", "H6", "PRE", "DIV", "ADDRESS"
start-tag
- - Odd that fieldset isn't mentioned, eh?


Right, the validator should have listed that too.


And a few other elements as well. The content model for FORM in the
Strict version is

(%block;|SCRIPT)+ -(FORM)

and %block is defined by

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

Thus, the "validator" issues an arbitrary sublist of the allowed
elements, in an arbitrary order. I'm using quotation marks here, because
the validator isn't really don't the job of a validator in this
particular issue. A validator must report reportable markup errors; it is
not required to do that in any particular, e.g. optimally understandable,
way. But it's clearly against the spirit to give misleading messages that
strongly suggest that _only_ elements from a particular set would be
allowed. The message given seems to be a fixed string that the
"validator" spits out in certain conditions, even in situations where
you validate against a customized DTD that does _not_ allow the elements
listed in the message as children of FORM!

It's just trying to be helpful in practice. This is how so many
confusions emerge.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html

Jul 20 '05 #8

P: n/a
Jukka K. Korpela wrote:
<!ENTITY % block
"P | %heading; | %list; | %preformatted; | DL | DIV | NOSCRIPT |
BLOCKQUOTE | FORM | HR | TABLE | FIELDSET | ADDRESS">

Thus, the "validator" issues an arbitrary sublist of the allowed
elements, in an arbitrary order.


Not so arbitrary.

It lists them in the order specified in the DTD and lists only those which
may have an <input> as the first child element.

P first, then the %headings (H1, H2, etc), then PRE. DL is skipped as you
would need a DT/DL to contain the input. It shows DIV, but skips NOSCRIPT
(which IIRC has the same content model as <body> and <form> so would need a
block element as the next child), likewise BLOCKQUOTE and FORM are skipped.
HR can't have children at all, TABLE needs TR and TD/TH (and optionally
THEAD/TBODY/TFOOT). FIELDSET has to start with a LEGEND and ADDRESS is
shown.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Jul 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.