Валидность форм

Проверяя на валидность документ я обнаружил, что конструкция вида <form action="#"><input type="button" /></form> считается невалидной с точки зрения валидатора, при указании типа документа XHTML 1.0 Strict или выше. И очень просит для себя таблетку в виде обертки контрола в теги вроде div, h1-h6, p и т. д.

Вот что выдает валидатор на простецкую формочку:

#  Error  Line 9, Column 39: document type does not allow element "input" here; missing one of "ins", "del", "h1", "h2", "h3", "h4", "h5", "h6", "p", "div", "address", "fieldset" start-tag.

<form action="#"><input type="button" /></form>

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>").

Валидной форма считается только та, контролы которой обернуты хотя бы одним из перечисленных тегов. А в xhtml1-strict.dtd написано:

<!--=================== Text Elements ====================================-->

<!ENTITY % special.pre
   "br | span | bdo | map">

<!ENTITY % special
   "%special.pre; | object | img ">

<!ENTITY % fontstyle "tt | i | b | big | small ">

<!ENTITY % phrase "em | strong | dfn | code | q |
                   samp | kbd | var | cite | abbr | acronym | sub | sup ">

<!ENTITY % inline.forms "input | select | textarea | label | button">

<!-- these can occur at block or inline level -->
<!ENTITY % misc.inline "ins | del | script">

<!-- these can only occur at block level -->
<!ENTITY % misc "noscript | %misc.inline;">

<!ENTITY % inline "a | %special; | %fontstyle; | %phrase; | %inline.forms;">

<!-- %Inline; covers inline or "text-level" elements -->
<!ENTITY % Inline "(#PCDATA | %inline; | %misc.inline;)*">

<!--================== Block level elements ==============================-->

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

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

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

<!-- %Flow; mixes block and inline and is used for list items etc. -->
<!ENTITY % Flow "(#PCDATA | %block; | form | %inline; | %misc;)*">

<!--================== Content models for exclusions =====================-->

<!-- a elements use %Inline; excluding a -->

<!ENTITY % a.content
   "(#PCDATA | %special; | %fontstyle; | %phrase; | %inline.forms; | %misc.inline;)*">

<!-- pre uses %Inline excluding big, small, sup or sup -->

<!ENTITY % pre.content
   "(#PCDATA | a | %fontstyle; | %phrase; | %special.pre; | %misc.inline;
      | %inline.forms;)*">

<!-- form uses %Block; excluding form -->

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

<!-- button uses %Flow; but excludes a, form and form controls -->

<!ENTITY % button.content
   "(#PCDATA | p | %heading; | div | %lists; | %blocktext; |
    table | %special; | %fontstyle; | %phrase; | %misc;)*">

То есть форма считается блоковым элементом а контрол — строчным, а не наоборот. Я, быть может, не так все понимаю, но это ошибка валидатора. Повнимательней почитал этот документ и узрел, что внутри формы находиться могут только блочные элементы, по крайней мере мне это кажется странным.

Вот что мне выдал HTML Tidy:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content="HTML Tidy for Linux (vers 6 November 2007), see www.w3.org" />
<title></title>
</head>
<body>
<form action="#"><input type="button" /></form>
</body>
</html>

После этого можно думать, стоит ли доверять валидатору. Валидатору оказалось верить можно, но все равно какая то неразбериха.

23 Март 2009

Комментарии

Так оберни ;)
И да, input type=button? Тэг button есть же!
P.S. ‘блоковые’ исправь на ‘блочные’
P.P.S. Можешь отключить необходимость предпросмотра в этом твоём textpattern? И Он Почему-то Ставит Большие Буквы В Каждом Слове %)

#lol2Fast4U · 27 Март 2009, 18:21 · Reply

я вот тоже думаю обернуть, но в какие именно хз.. валидатор выдал:
document type does not allow element «form» here; missing one of «object», «applet», «map», «iframe», «ins», «del» start-tag
выходит что <form> вобще запрещен в данных условиях без обертки в какой-нибудь <object> че делать то?

#bat · 15 Июнь 2009, 06:12 · Reply

Оберни в <div> и всех делов то.

#Werdn · 15 Июнь 2009, 19:59 · Reply

обернул.. вместо 62 ошибок стало 103 и валидатор начал ругаться на <div>:
document type does not allow element «div» here; missing one of «object», «applet», «map», «iframe», «button», «ins», «del» start-tag

#bat · 16 Июнь 2009, 05:32 · Reply

А куда пытаешься поцепить эту форму? Код в студию!

#Werdn · 17 Июнь 2009, 02:29 · Reply

попробуй прописать такой доктайп
<!DOCTYPE html PUBLIC «-//W3C//DTD XHTML 1.0 Transitional//EN» «http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd»>

#mexe · 31 Июль 2009, 18:58 · Reply
Комментирование этой статьи закрыто.