This patch includes the form preprocess function in addition to a form twig template. I've tested this and looks great to me.

CommentFileSizeAuthor
#1 1822210-form-2.patch1.49 KBEVIIILJ
d8tts-form.patch1.55 KBEVIIILJ

Comments

EVIIILJ’s picture

StatusFileSize
new1.49 KB

We might just want to kill the div for XHTML compliance within the twig template. Here's a patch including that change.

vlad.dancer’s picture

Status: Needs review » Reviewed & tested by the community

I'm agree with you. RTBC

jenlampton’s picture

Status: Reviewed & tested by the community » Active

I'm going to commit this template to the front-end branch with the inner div (even though I agree with you). The comment in form.inc indicates that the div inside the form is required for XHTML compliance, can someone please confirm that removing it won't get us in trouble?

I'll add a TODO in the template so we can revisit the div removal, after someone does some research on compliance, since I dunno anything about it :)

decafdennis’s picture

Title: Create preprocess function for theme_form » Investigate removing the inner div in form.html.twig

For background on the DIV inside the FORM element, see #690980: Disabled form elements not properly rendered.

jwilson3’s picture

Component: Twig templates » Twig templates conversion (front-end branch)

I just scanned #690980: Disabled form elements not properly rendered, and could find no reference about the inner div. Additionally, investigating one of the patches on that issue, even though that line was changed, it looks like the inner div existed before that issue.

From http://drupal.org/files/issues/drupal.form-disabled.102.patch

-  return '<form '. $action .' method="'. $element['#method'] .'" id="'. $element['#id'] .'"'. drupal_attributes($element['#attributes']) .">\n<div>". $element['#children'] ."\n</div></form>\n";
+  $element['#attributes']['id'] = $element['#id'];
+  // Anonymous DIV to satisfy XHTML compliance.
+  return '<form' . drupal_attributes($element['#attributes']) . '><div>' . $element['#children'] . '</div></form>';
 }

We still need to find out where the inner DIV was introduced, and read about why.

jwilson3’s picture

A quick search through the git history turned up a commit eb030cb9d8839bd08cb2bd1e4f954efe37047303 from 2003 when the inner DIV was first added, whose commit message was "Improvements: XHTML-ifications. Patch by GmbH.", so it could be that the inner div was for Xhtml compliance.

I used git log -S\</div\>\</form\> to search the git history.

jwilson3’s picture

My guess, from studying the XHTML DTD is that the inner div is there to ensure that you get valid XHTML, because <form><input/></form> (according to the XHTML dtd, is invalid), but <form><div><input/></div></form> is valid.

<!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">

In plain english, the only valid elements inside the FORM tag include:

NOSCRIPT, INS, DEL, SCRIPT, P, H1-6, DIV, UL/OL/DL, PRE, HR, BLOCKQUOTE, ADDRESS, FIELDSET, TABLE.

and, INPUT is not a tag in that list.

On the other hand, the HTML 5.1 nightly draft specifically shows an example HTML snippet in the section about the form element that uses: <form><label><input></form>.

jwilson3’s picture

Does anyone know what is the official stance for XHTML support in Drupal 8?

Project: » Lost & found issues

This issue’s project has disappeared. Most likely, it was a sandbox project, which can be deleted by its maintainer. See the Lost & found issues project page for more details. (The missing project ID was 1750250)