form

form 要素 (HTML)

[23] HTMLform 要素は、 フォーム包含子です。フォームの配置と提出先・提出方法を記述します。

[24] 仕様書:

[25]

状態
W3C 勧告
名前空間URI
http://www.w3.org/1999/xhtml
局所名
form (フォーム (form) より)
開始タグ
必須
終了タグ
必須
内容モデル
零個以上のブロック水準要素 (例外規定あり: >>39)
出現できる文脈
ブロック水準要素が認められる場所、または head子供として

[29] HTML 4 DTD 注釈 (参考) では interactive form (対話的フォーム) と説明されています。

属性

[12] form 要素内容属性
属性名属性値既定値説明状態出典
accept%ContentTypes受入れ媒体型[HTML 4]
accept-charset%Charsets受入れ charset[HTML 4]
action%URI(必須)フォーム処理器[HTML 4]
autocomplete自動補完非標準WinIE
class[HTML4] %coreattr
dir書字方向[HTML4] %i18n
enctype%ContentType提出媒体型[HTML 4]
id一意識別子[HTML4] %coreattr
lang自然言語[HTML4] %i18n
xml:lang自然言語[XHTML1]
lcs非標準iモード
measure非標準EMOBILE
methodget提出方式[HTML 4]
nameフォーム名[HTML 4]
onclick[HTML4] %events
ondblclick[HTML4] %events
onkeydown[HTML4] %events
onkeypress[HTML4] %events
onkeyup[HTML4] %events
onmousedown[HTML4] %events
onmousemove[HTML4] %events
onmouseout[HTML4] %events
onmouseover[HTML4] %events
onmouseup[HTML4] %events
onreset%Scriptフォーム再設定[HTML 4]
onsubmit%Scriptフォーム提出[HTML 4]
runatserver非標準
styleスタイル情報[HTML4] %coreattr
subject%Text主題
target%FrameTarget対象フレーム[HTML 4] 非推奨
title注釈的題[HTML4] %coreattr
utn(ブール型属性)()製造番号送信非標準iモード

[59] とほほでは urn 属性が紹介されていますが、 utn の誤りと見られます。

内容

[26] form 要素の内容としては、 フォームの配置 (layout) を記述します HTML 4 17.3。 具体的には、フォーム外同様の通常の内容マークに加えて、 フォーム制御子やフォーム制御子の (ラベル) を記述できます。

[11] input 要素などは行内要素扱いですから、 直接内容に持つことは出来ませんので注意が必要です。 (Transitional とかだと話は別ですが。) form の直接の子供になれるのは p 要素などのブロック水準要素です。

[31] HTML Working Group Voyager Issue Tracking System - Modularization-abstractions/591 http://hades.mn.aptest.com/cgi-bin/voyager-issues/Modularization-abstractions?id=591

Should we intentionally attempt to support the legacy content models in the legacy redecl module?

No - it _could_ break compatibility, and we don't want to do that in a second edition.

(名無しさん [sage] 2006-02-15 08:59:39 +00:00)

HTML 5 内容モデル

[39] Web Forms 2.0 では、次の内容が認められています WF2 2.3:

空要素

[32] Web Forms 2.0 では、 form 要素して構いません。 また、のとき、 head 内に入れることができます (>>33)。 WF2 2.3

form の入れ子

[16] form 要素の子孫に form 要素は存在できません XHTML 1.0

[36] Web Forms 2.0 では、 formform子孫にすることが認められています。 WF2 2.3

[37] HTML 直列化

(XHTML ではなく) HTML では、 form 要素内の <form> 開始タグは虫されるのが普通なので、 form入れ子は認められていません。 WF2 2.3

HTML として構文解析した文書でも、 DOM を通じて form 内に form を入れることはできます。

[38] フォーム間の関係

入れ子にしても、フォーム間に意味的な関係はありません。 フォーム制御子は通常直近の祖先であるフォームだけに関連付けられます。 フォーム関連の属性事象も、 (DOM で規定された通常通りの事象泡立ちはありますが) どちらかのフォームだけに関係します。

メモ

文脈

head の子供

[33] form は、内容の場合に限り、 head子供とすることができます。 WF2 2.3

[34] Web Forms 2.0 で導入された form 属性により、フォーム制御子form 外であっても特定の form と関連付けることができるようになりました。 従いまして、フォーム制御子は直接 body の子孫とし、それに対応する form 要素head 要素に入れるという使い方ができます。

これは、 XFormsフォームの定義方法とも似ています。

[35] HTML 直列化との関係

(XHTML ではなく) HTML では、 <form> 開始タグが出現すると body 要素開いている構文解析されてしまいます。

例えば、

<html>
<head>
<title>空の form の例</title>
<form></form>
<h1>空の <code lang="en">form</code> の例</h1>
</body>
</html>

<html>
<head>
<title>空の form の例</title>
</head><body><form></form>
<h1>空の <code lang="en">form</code> の例</h1>
</body>
</html>

と解釈されてしまいます。

そう解釈されてもフォームとしての機能は変わりありませんが、 DOM による操作や CSS によるレンダリングなどでの扱いが変わります。 また、他の要素タグの位置によっては文書不適合となります。
HTML として構文解析した文書でも、 後から DOM により head 内に form を入れることはできます。

状態

[3]

constructing entry list
planned navigation
提出イベント群発火中

メンバー

[2]

レンダリング

[57] head 内の非空 form

通常利用者エージェントhead 要素内容レンダリングしませんから、 でない formhead 内に含まれていても、 特別な処理は必要ありません。 CSS 等により head 要素内の formレンダリングすることにした場合、 form は通常通り (body 内と同じように) 動作しなければなりませんWF2 2.18

安全性

フォームの安全性の項を参照。

[27] 単純なフォームの例 HTML 4 27.3、改

 <FORM action="http://somesite.example/prog/adduser" method="post">
 ...form contents...
 </FORM>

このフォームの場合、提出すると adduser というフォーム処理エージェントに HTTP POST を使ってフォームのデータを送信します。

実装

[21] 伝統的にフォームの各欄に入力していても、 提出しないでブラウザを閉じたり他の頁に移動したりしたときに、 ブラウザは何も言ってくれません。頁移動はともかく、閉じてしまったら、 入力途中のデータは失われます。これって不親切だと思いませんか。 っていうか、間違って終了させちゃったんだよなあ。。。書きかけのデータが水の泡。。。

[22] >>21 とりあえず著者ができることとして、 onunload で check して終了をとめられないかなあ。

[28] 途中で別の作業が入って、また後から続きを・・・ と言うこともあるので、ブラウザに中途保存機能がついていると便利かも。 最近のブラウザはフォームの自動補完機能がついているものが多いですから、 利用者が意図的に保存できても良いはずです。

(嘆かわしいことですがブラウザや環境が突然動かなくなることがたまにありますから、 こまめに保存できるといいですよね。自動保存だとなお良い。)

[60] IE6 Form Tag Orphans by jpsykes (2007-09-29 12:45:21 +09:00 版) http://jpsykes.com/92/ie6-form-tag-orphans (名無しさん)

不思議解釈

[14] form 要素の典型的な既定スタイル・シートでのレンダリングでは form 要素の周囲に余白が空くことがあるので、 td 要素の内容にするときには <form> タグ<td> タグの外に出すといい、 という素晴らしき不思議マーク付け裏技があるそうです。

[30] nodeType 8 and getElementsByTagName - Anne’s Weblog about Markup & Style http://annevankesteren.nl/2005/10/msn-sessions

WinIE 6form タグのところで (も) 滅茶苦茶な文書木 (のようなもの) を作るというお話。 (名無しさん 2005-10-31 00:10:13 +00:00)

メモ

  • [17] mailto: URI のとき、 NN2 はその宛先のメイル作成画面を開きますが、それ以上は何もしてくれません。 (入力欄の値はまったく反映されません。)

[18] >>17 NC4.01 で試してみたら、同じ結果になりました。でも電子メイルで送信します云々の警告は出るので、対応はしてるはずなんですが。謎です。

  • [20] >>17 のようなのはブラウザと MUA の相性で今でもよくあることみたいです。というわけで、 JavaScript を使って無理矢理送らせる方法 : フォームの送信について http://www.parkcity.ne.jp/~chaichan/qanda/qa4468.htm。非本質的で呆れて物も言えなくなるような汚いやり方で、よくもまあこんなの思いつくなあという感じではありますが、誰も form + mailto: を標準化しようとしない以上どうしようもないのかも。

メモ

[62] (X)HTML5 Tracking ( 版) http://html5.org/tools/web-apps-tracker?from=2420&to=2421

[63] (X)HTML5 Tracking ( 版) http://html5.org/tools/web-apps-tracker?from=2527&to=2528

[64] (X)HTML5 Tracking ( 版) http://html5.org/tools/web-apps-tracker?from=2525&to=2526

[65] Web Forms 2.0 ( 版) http://www.whatwg.org/specs/web-forms/current-work/#form0

[66] (X)HTML5 Tracking ( 版) http://html5.org/tools/web-apps-tracker?from=4287&to=4288

[67] Bug 7978 – Form foster parenting introduces extra space to layout ( 版) http://www.w3.org/Bugs/Public/show_bug.cgi?id=7978

[68] (X)HTML5 Tracking ( 版) http://html5.org/tools/web-apps-tracker?from=4521&to=4522

[69] IRC logs: freenode / #whatwg / 20100404 ( 版) http://krijnhoetmer.nl/irc-logs/whatwg/20100404#l-150

[70] [whatwg] Constraint validation feedback (various threads) ( 版) http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2010-August/027882.html

[71] Opera: Opera 11.00 for Windows changelog ( (Frank M. Palinkas, Technical Writer, Opera Software ASA 著, 版)) http://www.opera.com/docs/changelogs/windows/1100/

[72] Web Applications 1.0 r6221 Remove <progress form> and <meter form> since they are basically useless. ( ( 版)) http://html5.org/tools/web-apps-tracker?from=6220&to=6221

[73] Web Applications 1.0 r6727 Try to make the named getter on HTMLFormElement more Web-compatible. ( ( 版)) http://html5.org/tools/web-apps-tracker?from=6726&to=6727

[74] [whatwg] Session Management ( ( 版)) http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2012-January/034331.html

[75] ふつうのformをつかいたい - はまちや2 - ニコニコ超会議2012 ( ( 版)) http://hamachiya.com/form/#slide1

[76] [whatwg] Localisation of form fields ( ( 版)) http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2012-May/035674.html

[77] Firefox 14 for developers - MDN ( ( 版)) https://developer.mozilla.org/en/Firefox_14_for_developers#HTML

[78] サーバーにパスワードを送らないフォームを作る - 金利0無利息キャッシング – キャッシングできます - subtech ( ( 版)) http://subtech.g.hatena.ne.jp/mala/20120703/1341322969

[79] Web Applications 1.0 r7305 forgot to fix the index (again) when removing form= from <progress> and <meter>.]] ( ( 版)) http://html5.org/tools/web-apps-tracker?from=7304&to=7305

[80] [whatwg] Forms-related feedback ( ( 版)) http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2013-January/038532.html

[81] HTML Form HTTP Extensions ( ( 版)) http://cameronjones.github.com/form-http-extensions/index.html

[82] Web Applications 1.0 r7722 Try to define order for supported property names. This is not based on testing. If there are compatibility constraints here that prevent implementing this as specced, please let me know. ( ( 版)) http://html5.org/tools/web-apps-tracker?from=7721&to=7722

[83] Web Applications 1.0 r7986 Be even more explicit about the supported property names of a <form>. ( ( 版)) http://html5.org/tools/web-apps-tracker?from=7985&to=7986

[84] Web Applications 1.0 r8041 Don't make form names enumerable. ( ( 版)) http://html5.org/tools/web-apps-tracker?from=8040&to=8041

[85] Web Applications 1.0 r8185 Make the <form> past names map associations go away when the form owner changes, not when the element is removed from the document. ( ( 版)) http://html5.org/tools/web-apps-tracker?from=8184&to=8185

[86] [whatwg] Elements should be removed from the past names map once it's no longer associated with the form element ( ( 版)) http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2013-September/040898.html

[87] [whatwg] Form-associated elements and the parser ( ( 版)) http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2013-December/041706.html

[88] WWW-Talk Apr-Jun 1994: NCSA Mosaic for X 2.3 available. ( ( 版)) http://1997.webhistory.org/www.lists/www-talk.1994q2/0134.html

[89] ncsa-mosaic/CHANGES at master · alandipert/ncsa-mosaic ( ( 版)) https://github.com/alandipert/ncsa-mosaic/blob/master/CHANGES#L227

[90] W3C HTML Form HTTP Extensions ( ( 版)) http://www.w3.org/TR/2014/WD-form-http-extensions-20140529/

[91] Bug 26521 – [[GetOwnProperty]] behavior for named properties is not web-compatible ( ( 版)) https://www.w3.org/Bugs/Public/show_bug.cgi?id=26521

[92] Web Applications 1.0 r8843 Update the way some of the selectors are written to use more modern selector features. ( ( 版)) https://html5.org/r/8843

[93] draft-pfeiffer-remoteaccess-00 - Remote Access to Embedded Devices ( ( 版)) https://tools.ietf.org/html/draft-pfeiffer-remoteaccess-00#section-2.1

[1] Fix #703: Make form.imageName return non-descendant <img> · whatwg/html@40fa464 ( 版) https://github.com/whatwg/html/commit/40fa4643dbf0ba004a938444fd4a370a1d3a53e2

[4] Issue 106: The <form> element should only map to FORM landmark with r… (jongund著, ) https://github.com/w3c/html-aam/commit/bd7cfedfae9f53c0954c45273af33798d1e5ca75

[5] Issue 106: The <form> element should only map to FORM landmark with restriction of accessible name by jongund · Pull Request #107 · w3c/html-aam () https://github.com/w3c/html-aam/pull/107

[6] The <form> element should only map to FORM landmark with restriction of accessible name · Issue #106 · w3c/html-aam () https://github.com/w3c/html-aam/issues/106

[7] added mapping for form with acc name (stevefaulkner著, ) https://github.com/w3c/html-aam/commit/2724b297db1f0bc129bc4fdf711e6c48cf9ac1e4

[8] The <form> element should only map to FORM landmark with restriction of accessible name · Issue #106 · w3c/html-aam () https://github.com/w3c/html-aam/issues/106

[9] Add the autocapitalize attribute (rlanday著, ) https://github.com/whatwg/html/commit/f1f0af83e320f14a59dc4e552ee82aab7908f00c

[10] Restrict the main element to be used once per document (annevk著, ) https://github.com/whatwg/html/commit/1dec930b3df93c799d5f3f685a46940913476086