home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / the_web / documents / spec / html_spec / forms_sgm < prev    next >
Encoding:
Text File  |  1995-08-04  |  14.4 KB  |  447 lines

  1. <!-- $Id -->
  2. <h1 id=forms>Forms
  3.  
  4. <p>A form is a template for a form data set and an associated method
  5. and action URI. A form data set is a sequence of name/value pair
  6. fields. The names are specified on the <attr/NAME/ attributes of form
  7. input elements, and the values are given initial values by various
  8. forms of markup and edited by the user. The resulting form data set is
  9. used to access an information service as a function of the action and
  10. method.
  11.  
  12. <p>Forms elements can be mixed in with document structuring
  13. elements. For example, a <tag/PRE/ element may contain a <tag/FORM/
  14. element, or a <tag/FORM/ element may contain lists which contain
  15. <tag/INPUT/ elements. This gives considerable flexibility in
  16. designing the layout of forms.
  17.  
  18. <p> Form processing is a level 2 feature.
  19.  
  20. <h2>Form Elements
  21.  
  22. <h3>Form: FORM
  23.  
  24. <p>The <tag/FORM/ element contains a sequence of input elements, along
  25. with document structuring elements. The attributes are:
  26.  
  27. <tl>
  28. <tli>ACTION: specifies the action URI for the form. The action URI of
  29. a form defaults to the base URI of the document (see <hdref
  30. refid=hyperlink>).
  31.  
  32. <tli>METHOD: selects a method of accessing the action URI. The set of
  33. applicable methods is a function of the scheme of the action URI of
  34. the form. See <hdref refid=queryf> and <hdref refid=formpost>.
  35.  
  36. <tli>ENCTYPE: specifies the media type used to encode the name/value
  37. pairs for transport, in case the protocol does not itself impose a
  38. format. See <hdref refid=urlencode>.
  39.  
  40. </tl>
  41.  
  42. <h3 id=input>Input Field: INPUT
  43.  
  44. <p>The <tag/INPUT/ element represents a field for user input. The
  45. <attr/TYPE/ attribute discriminates between several variations of
  46. fields.
  47.  
  48. The <tag/INPUT/ element has a number of attributes. The set of
  49. applicable attributes depends on the value of the <attr/TYPE/
  50. attribute. 
  51.  
  52. <h4>Text Field: INPUT TYPE=TEXT
  53.  
  54. <p>The default vaule of the <attr/TYPE/ attribute is <code/TEXT/,
  55. indicating a single line text entry fields. (Use the <tag/TEXTAREA/
  56. element for multi-line text fields.)
  57.  
  58. <p>Required attributes are:
  59.  
  60. <tl>
  61. <tli>NAME: name for the form field corresponding to this
  62. element.
  63. </tl>
  64.  
  65. The optional attriubtes are:
  66.  
  67. <tl>
  68. <tli>MAXLENGTH: constrains the number of characters that can be
  69. entered into a text input field. If the value of <attr/MAXLENGTH/ is
  70. greater the the value of the <attr/SIZE/ attribute, the field should
  71. scroll appropriately. The default number of characters is unlimited.
  72.  
  73. <tli>SIZE: specifies the amount of display space allocated to this
  74. input field according to its type. The default depends on the user
  75. agent.
  76.  
  77. <tli>VALUE: The initial value of the field.
  78. </tl>
  79.  
  80.  
  81. <p> For example:
  82.  
  83. <listing><![CDATA[
  84. <p>Street Address: <input name=street><br>
  85. Postal City code: <input name=city size=16 maxlength=16><br>
  86. Zip Code: <input name=zip size=10 maxlength=10 value="99999-9999"><br>
  87. ]]></listing>
  88.  
  89. <h4>Password Field: INPUT TYPE=PASSWORD
  90.  
  91. An <tag/INPUT/ element with <code/TYPE=PASSWORD/ is a text field as
  92. above, except that the value is obscured as it is entered. (see also:
  93. <hdref refid=security>).
  94.  
  95. <p> For example:
  96.  
  97. <listing><![CDATA[
  98. <p>Name: <input name=login> Password: <input type=password name=passwd>
  99. ]]></listing>
  100.  
  101. <h4>Check Box: INPUT TYPE=CHECKBOX
  102.  
  103. <p> An <tag/INPUT/ element with <code/TYPE=CHECKBOX/ represents a
  104. boolean choice. A set of such elements with the same name represents
  105. an n-of-many choice field. Required attributes are:
  106.  
  107. <tl>
  108. <tli>NAME: symbolic name for the form field corresponding to this
  109. element or group of elements.
  110.  
  111. <tli>VALUE: The portion of the value of the field contributed by this
  112. element.
  113. </tl>
  114.  
  115. <p>Optional attributes are:
  116.  
  117. <tl>
  118. <tli>CHECKED: indicates that the initial state is on.
  119. </tl>
  120.  
  121.  
  122. <p>For example:
  123.  
  124. <listing><![CDATA[
  125. <p>What flavors do you like?
  126. <input type=checkbox name=flavor value=vanilla>Vanilla<br>
  127. <input type=checkbox name=flavor value=strawberry>Strawberry<br>
  128. <input type=checkbox name=flavor value=chocolate checked>Chocolate<br>
  129. ]]></listing>
  130.  
  131. <h4>Radio Button: INPUT TYPE=RADIO
  132.  
  133. <p>An <tag/INPUT/ element with <code/TYPE=RADIO/ represents a boolean
  134. choice. A set of such elements with the same name represents a
  135. 1-of-many choice field. The <attr/NAME/ and <attr/VALUE/ attributes
  136. are required as for check boxes. Optional attributes are:
  137.  
  138. <tl>
  139. <tli>CHECKED: indicates that the initial state is on.
  140. </tl>
  141.  
  142. <p>At all times, exactly one of the radio buttons in a set is
  143. checked. If none of the <tag/INPUT/ elements of a set of radio buttons
  144. specifies <code/CHECKED/, then the user agent must check the first
  145. radio button of the set initially.
  146.  
  147. <p>For example:
  148.  
  149. <listing><![CDATA[
  150. <p>Which is your favorite?
  151. <input type=radio name=flavor value=vanilla>Vanilla<br>
  152. <input type=radio name=flavor value=strawberry>Strawberry<br>
  153. <input type=radio name=flavor value=chocolate>Chocolate<br>
  154. ]]></listing>
  155.  
  156. <h4>Image Pixel: INPUT TYPE=IMAGE
  157.  
  158. <p>An <tag/INPUT/ element with <code/TYPE=IMAGE/ specifies an image
  159. resource to display, and allows input of two form fields: the x and y
  160. coordinate of a pixel chosen from the image. The names of the fields
  161. are the name of the field with <code/.x/ and <code/.y/
  162. appended. <code/TYPE=IMAGE/ implies <code/TYPE=SUBMIT/ processing;
  163. that is, when a pixel is chosen, the form as a whole is submitted.
  164.  
  165. <p>The <attr/NAME/ attribute is required as for other input
  166. fields. The <attr/SRC/ attribute is required and the <attr/ALIGN/ is
  167. optional as for the <tag/IMG/ element (see <hdref refid=img>).
  168.  
  169. <p>For example:
  170.  
  171. <listing><![CDATA[
  172. <p>Choose a point on the map:
  173. <input type=image name=point src="map.gif">
  174. ]]></listing>
  175.  
  176. <h4>Hidden Field: INPUT TYPE=HIDDEN
  177.  
  178. <p>An <tag/INPUT/ element with <code/TYPE=HIDDEN/ represents a hidden
  179. field.The user does not interact with this field; instead, the
  180. <attr/VALUE/ attribute specifies the value of the field. The
  181. <attr/NAME/ and <attr/VALUE/ attributes are required.
  182.  
  183. <p>For example:
  184.  
  185. <listing><![CDATA[
  186. <input type=hidden name=context value="l2k3j4l2k3j4l2k3j4lk23">
  187. ]]></listing>
  188.  
  189. <h4>Submit Button: INPUT TYPE=SUBMIT
  190.  
  191. An <tag/INPUT/ element with <code/TYPE=SUBMIT/ represents an input
  192. option, typically a button, that instructs the user agent to submit
  193. the form. Optional attributes are:
  194.  
  195. <tl>
  196. <tli>NAME: indicates that this element contributes a form field whose
  197. value is given by the <attr/VALUE/ attribute. If the <attr/NAME/
  198. attribute is not present, this element does not contribute a form
  199. field.
  200.  
  201. <tli>VALUE: indicates a label
  202. for the input (button).
  203. </tl>
  204.  
  205. <listing><![CDATA[
  206. You may submit this request internally:
  207. <input type=submit name=recipient value=internal><br>
  208. or to the external world:
  209. <input type=submit name=recipient value=world>
  210. ]]></listing>
  211.  
  212. <h4>Reset Button: INPUT TYPE=RESET
  213.  
  214. An <tag/INPUT/ element with <code/TYPE=RESET/ represents an input
  215. option, typically a button, that instructs the user agent to reset the
  216. form's fields to their initial states. The <attr/VALUE/ attribute, if
  217. present, indicates a label for the input (button).
  218.  
  219. <listing><![CDATA[
  220. When you are finished, you may submit this request:
  221. <input type=submit><br>
  222. You may clear the form and start over at any time: <input type=reset>
  223. ]]></listing>
  224.  
  225. <h3>Selection: SELECT
  226.  
  227. <p>The <tag/SELECT/ element constrains the form field to an enumerated
  228. list of values. The values are given in <tag/OPTION/ elements.
  229. Attributes are:
  230.  
  231. <tl>
  232. <tli>MULTIPLE: indicates that more than one option may be included in
  233. the value.
  234.  
  235. <tli>NAME: specifies the name of the form field.
  236.  
  237. <tli>SIZE: specifies the number of visible items. Select fields of
  238. size one are typically pop-down menus, whereas select fields with size
  239. greater than one are typically lists.
  240.  
  241. </tl>
  242.  
  243. <p> For example:
  244.  
  245. <listing><![CDATA[
  246. <SELECT NAME="flavor">
  247. <OPTION>Vanilla
  248. <OPTION>Strawberry
  249. <OPTION value="RumRasin">Rum and Raisin
  250. <OPTION selected>Peach and Orange
  251. </SELECT>
  252. ]]></listing>
  253.  
  254. <p>The initial state has the first option selected, unless a
  255. <attr/SELECTED/ attribute is present on any of the <tag/OPTION/
  256. elements.
  257.  
  258. <h4>Option: OPTION
  259.  
  260. <p>The Option element can only occur within a Select element. It
  261. represents one choice, and has the following attributes:
  262.  
  263. <tl>
  264. <tli>SELECTED: Indicates that this option is initially selected.
  265.  
  266. <tli>VALUE: indicates the value to be returned if this
  267. option is chosen. The field value defaults to the content of the
  268. <tag/OPTION/ element.
  269. </tl>
  270.  
  271. <p>The content of the <tag/OPTION/ element is presented to the user to
  272. represent the option. It is used as a returned value if the VALUE
  273. attribute is not present.
  274.  
  275. <h3>Text Area: TEXTAREA
  276.  
  277. <p>The <tag/TEXTAREA/ element represents a multi-line text
  278. field. Attributes are:
  279.  
  280. <tl>
  281. <tli>COLS: the number of visible columns to display for the text area,
  282. in characters.
  283. <tli>NAME: Specifies the name of the form field.
  284. <tli>ROWS: The number of visible rows to display for the text area, in
  285. characters.
  286. </tl>
  287.  
  288. <p>For example:
  289.  
  290. <listing><![CDATA[
  291. <TEXTAREA NAME="address" ROWS=6 COLS=64>
  292. HaL Computer Systems
  293. 1315 Dell Avenue
  294. Campbell, California 95008
  295. </TEXTAREA>
  296. ]]></listing>
  297.  
  298. <p>The content of the <tag/TEXTAREA/ element is the field's initial
  299. value.
  300.  
  301. <p>Typically, the ROWS and COLS attributes determine the visible
  302. dimension of the field in characters. The field is typically rendered
  303. in a fixed-width font. HTML user agents should allow text to extend
  304. beyond these limits by scrolling as needed.
  305.  
  306. <h2>Form Submission
  307.  
  308. <p> An HTML user agent begins processing a form by presenting the
  309. document with the fields in their initial state. The user is allowed
  310. to modify the fields, constrained by the field type etc. When the user
  311. indicates that the form should be submitted (using a submit button or
  312. image input), the form data set is processed according to its method,
  313. action URI and enctype.
  314.  
  315. <p>When there is only one single-line text input field in a form, the
  316. user agent should accept Enter in that field as a request to submit
  317. the form.
  318.  
  319. <h3 id=urlencode>The form-urlencoded Media Type
  320.  
  321. <p>The default encoding for all forms is
  322. <code>application/x-www-form-urlencoded</>. A form data set is
  323. represented in this media type as follows:
  324.  
  325. <ol>
  326. <li>The form field names and values are escaped: space characters are
  327. replaced by <code/+/, and then reserved characters are escaped as per
  328. [URL]; that is, non-alphanumeric characters are replaced by
  329. <code/%HH/, a percent sign and two hexadecimal digits representing the
  330. ASCII code of the character. Line breaks, as in multi-line text field
  331. values, are represented as CR LF pairs, i.e. <code/%0D%0A/.
  332.  
  333. <li>The fields are listed in the order they appear in the document
  334. with the name separated from the value by <code/=/ and the pairs
  335. separated from each other by <code/&/. Fields with null values may be
  336. omitted. In particular, unselected radio buttons and checkboxes should
  337. not appear in the encoded data, but hidden fields with <attr/VALUE/
  338. attributes present should.
  339. <note>The URI from a query form submission can be used in a normal
  340. anchor style hyperlink. Unfortunately, the use of the <code/&/
  341. character to separate form fields interacts with its use in SGML
  342. attribute values as an entity reference delimiter. For example, the
  343. URI <code><![CDATA[http://host/?x=1&y=2]]></> must be written
  344. <code><![CDATA[<a href="http://host/?x=1&y=2"]]></code> or
  345. <code><![CDATA[<a href="http://host/?x=1&y=2">]]></>.
  346.  
  347. <p>HTTP server implementors, and in particular, CGI implementors are
  348. encouraged to support the use of <code/;/ in place of <code/&/ to save
  349. users the trouble of escaping <code/&/ characters this way.
  350. </note>
  351. </ol>
  352.  
  353. <h3 id=queryf>Query Forms: METHOD=GET
  354.  
  355. <p>If the processing of a form is idempotent (i.e. it has no lasting
  356. observable effect on the state of the world), then the form method
  357. should be <code/GET/. Many database searches have no visible
  358. side-effects and make ideal applications of query forms.
  359.  
  360. <p>To process a form whose action URL is an HTTP URL and whose method
  361. is <code/GET/, the user agent starts with the action URI and appends a
  362. <code/?/ and the form data set, in
  363. <code>application/x-www-form-urlencoded</> format as above.  The user
  364. agent then traverses the link to this URI just as if it were an anchor
  365. (see <hdref refid=traverse>).
  366. <note>
  367. The URL encoding may result in very long URIs, which cause some
  368. historical HTTP server implementations to exhibit defective behavior.
  369. As a result, some HTML forms are written using <code/METHOD=POST/ even
  370. though the form submission has no side-effects.
  371. </note>
  372.  
  373. <h3 id=formpost>Forms with Side-Effects: METHOD=POST
  374.  
  375. <p>If the service associated with the processing of a form has side
  376. effects (for example, modification of a database or subscription to a
  377. service), the method should be <code/POST/.
  378.  
  379. <p>To process a form whose action URL is an HTTP URL and whose method
  380. is <code/POST/, the user agent conducts an HTTP POST transaction using
  381. the action URI, and a message body of type
  382. <code>application/x-www-form-urlencoded</> format as above. The user
  383. agent should display the response from the HTTP POST interaction just
  384. as it would display the response from an HTTP GET above.
  385.  
  386.  
  387. <h3>Example Form Submission: Questionnaire Form
  388.  
  389. <p>Consider the following document:
  390.  
  391. <listing><![CDATA[
  392. <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
  393. <title>Sample of HTML Form Submission</title>
  394. <H1>Sample Questionnaire</H1>
  395. <P>Please fill out this questionnaire:
  396. <FORM METHOD="POST" ACTION="http://www.w3.org/sample">
  397. <P>Your name: <INPUT NAME="name" size="48">
  398. <P>Male <INPUT NAME="gender" TYPE=RADIO VALUE="male">
  399. <P>Female <INPUT NAME="gender" TYPE=RADIO VALUE="female">
  400. <P>Number in family: <INPUT NAME="family" TYPE=text>
  401. <P>Cities in which you maintain a residence:
  402. <UL>
  403. <LI>Kent <INPUT NAME="city" TYPE=checkbox VALUE="kent">
  404. <LI>Miami <INPUT NAME="city" TYPE=checkbox VALUE="miami">
  405. <LI>Other <TEXTAREA NAME="other" cols=48 rows=4></textarea>
  406. </UL>
  407. Nickname: <INPUT NAME="nickname" SIZE="42">
  408. <P>Thank you for responding to this questionnaire.
  409. <P><INPUT TYPE=SUBMIT> <INPUT TYPE=RESET>
  410. </FORM>
  411. ]]></listing>
  412.  
  413. <p>The initial state of the form data set is:
  414.  
  415. <tl>
  416. <tli>name: ""
  417. <tli>gender: "male"
  418. <tli>family: ""
  419. <tli>other: ""
  420. <tli>nickname: ""
  421. </tl>
  422.  
  423. <p>Note that the radio input has an initial value, while the checkbox
  424. has none.
  425.  
  426. <p>The user might edit the fields and request that the form be
  427. submitted. At that point, suppose the values are:
  428.  
  429. <tl>
  430. <tli>name: "John Doe"
  431. <tli>gender: "male"
  432. <tli>family: "5"
  433. <tli>city: "kent"
  434. <tli>city: "miami"
  435. <tli>other: "abc\ndef"
  436. <tli>nickname: "J&D"
  437. </tl>
  438.  
  439. <p>The user agent then conducts an HTTP POST transaction using the URI
  440. <code>http://www.w3.org/sample</>. The message body would be (ignore
  441. the line break):
  442.  
  443. <listing><![CDATA[
  444. name=John+Doe&gender=male&family=5&city=kent&city=miami&
  445. other=abc%0D%0Adef&nickname=J%26D
  446. ]]></listing>
  447.