Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In XHTML 1.1: element 'input' cannot be nested within element 'form'. Why?

Tags:

xhtml

This below code is forbidden in XHTML 1.1 strict mode:

<form method="post" action="index">
    <input id="_method" name="_method" type="hidden" value="" />
</form>

If you want it to be valid then you need to wrap it with a div (or p, etc..) like:

<form method="post" action="index">
    <div>
         <input id="_method" name="_method" type="hidden" value="" />
    </div>
</form>

How does this make any sense at all?

like image 267
Fitzchak Yitzchaki Avatar asked Jan 28 '10 22:01

Fitzchak Yitzchaki


2 Answers

According to the W3C and this site the <form> element in XHTML 1.1 may only contain block level elements and <fieldset>.


As for why ... I believe that the reason that form may only contain block-level elements is because it is not considered an element in itself, but rather a wrapper around other elements. There was some discussion of this in the w3c's mailing lists some years ago that I was able to dig up -- but nothing that actually answered the question.

like image 181
Sean Vieira Avatar answered Nov 19 '22 10:11

Sean Vieira


Welcome to the wacky world of standards. Sometimes it seemed like the folks writing XHTML standards thought the language would be better if it had more rules.

HTML5 is here now.

like image 34
Paul D. Waite Avatar answered Nov 19 '22 09:11

Paul D. Waite