Html 5.2 --> Form submission

https://www.w3.org/TR/html52/sec-forms.html#forms-form-submission

Html 5.2  --> Form submission

 

 

旧版本https://www.w3.org/TR/html401/interact/forms.html#h-17.13

17.13 Form submission

The following sections explain how user agents submit form data to form processing agents.

17.13.1 Form submission method

The method attribute of the FORM element specifies the HTTP method used to send the form to the processing agent. This attribute may take two values:

  • get:With the HTTP "get" method, the form data set is appended to the URI specified by the action attribute (with a question-mark ("?") as separator) and this new URI is sent to the processing agent.
  • post:With the HTTP "post" method, the form data set is included in the body of the form and sent to the processing agent.

The "get" method should be used when the form is idempotent (i.e., causes no side-effects). Many database searches have no visible side-effects and make ideal applications for the "get" method.

If the service associated with the processing of a form causes side effects (for example, if the form modifies a database or subscription to a service), the "post" method should be used.

Note. The "get" method restricts form data set values to ASCII characters. Only the "post" method (with enctype="multipart/form-data") is specified to cover the entire [ISO10646] character set.

 

17.13.2 Successful controls

A successful control is "valid" for submission. Every successful control has its control name paired with its current value as part of the submitted form data set. A successful control must be defined within a FORM element and must have a control name.

However:

  • Controls that are disabled cannot be successful.
  • If a form contains more than one submit button, only the activated submit button is successful.
  • All "on" checkboxes may be successful.
  • For radio buttons that share the same value of the name attribute, only the "on" radio button may be successful.
  • For menus, the control name is provided by a SELECT element and values are provided by OPTION elements. Only selected options may be successful. When no options are selected, the control is not successful and neither the name nor any values are submitted to the server when the form is submitted.
  • The current value of a file select is a list of one or more file names. Upon submission of the form, the contents of each file are submitted with the rest of the form data. The file contents are packaged according to the form's content type.
  • The current value of an object control is determined by the object's implementation.

If a control doesn't have a current value when the form is submitted, user agents are not required to treat it as a successful control.

Furthermore, user agents should not consider the following controls successful:

Hidden controls and controls that are not rendered because of style sheet settings may still be successful. For example:

<FORM action="..." method="post">
<P>
<INPUT type="password" style="display:none"  
          name="invisible-password"
          value="mypassword">
</FORM>

will still cause a value to be paired with the name "invisible-password" and submitted with the form.

17.13.3 Processing form data

When the user submits a form (e.g., by activating a submit button), the user agent processes it as follows.

Step one: Identify the successful controls 

Step two: Build a form data set 

A form data set is a sequence of control-name/current-value pairs constructed from successful controls

form提交的时候,会用control name:current value来构建form data

Step three: Encode the form data set 

The form data set is then encoded according to the content type specified by the enctype attribute of the FORM element.

Step four: Submit the encoded form data set 

Finally, the encoded data is sent to the processing agent designated by the action attribute using the protocol specified by the method attribute.

This specification does not specify all valid submission methods or content types that may be used with forms. However, HTML 4 user agents must support the established conventions in the following cases:

  • If the method is "get" and the action is an HTTP URI, the user agent takes the value of action, appends a`?'to it, then appends the form data set, encoded using the "application/x-www-form-urlencoded" content type. The user agent then traverses the link to this URI. In this scenario, form data are restricted to ASCII codes.
  • If the method is "post" and the action is an HTTP URI, the user agent conducts an HTTP "post" transaction using the value of the action attribute and a message created according to the content type specified by the enctype attribute.

For any other value of action or method, behavior is unspecified.

User agents should render the response from the HTTP "get" and "post" transactions.

 

上一篇:CF乱做


下一篇:Codeforces Round #626 部分题解