Which data be post to the server when submitting a form

Source: Internet
Author: User
1, HTML Specification

In HTML specification, a section of [Form submission] dedicated to explain which data shocould be post to the sever when submitting a form. user Agent (such as chrome, ie) which compliant with the specification will send [form data set] to the server by HTTP protocol.

 

In general, form data set is a key/value pairs in which contains a number of name/value extracted by HTML element. not all of HTML element value will be extracted, only successful controls will be extracted and combine together as form data set.

 

Any elements that have the attribute of name and value is a successful control, doesn t:

  1. Controls that are disabled cannot be successful.
  2. If a form contains more than one submit button, only the activated submit button is successful.
  3. All "on" checkboxes may be successful.
  4. For radio buttons that share the same value ofNameAttribute, only the "on" radio button may be successful.
  5. For menus, the control name is provided bySelectElement and values are providedOptionElements. 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.
  6. The current value of a file select is a list of one or more file names. Upon submission of the form,ContentsOf each file are submitted with the rest of the form data. The file contents are packaged according to the form's content type.
  7. The current value of an object control is determined by the object's implementation.
  8. 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.

 

Please refer to specification for details.

 

2, Example

If you have a web page like this:

<HTML> 

We type some words and click some checkboxes, as following example. Which element's value will be sent after clicking submit button?

 

The answer (using firebug) to the example is:

 

Some question you may ask?

Q: Why Radioa do not extract as name/value pair?

A: Radio controls do not set the name attribute. if the radio control contains a atrriw.called name, as <input id = "radio1" type = "radio" name = "radio1"/> <span> Radioa </span>, it will be extracted as name/value pair and send to server.

 

Q: How to extract the value in server-side by Asp.net?

A: You want to extract value of user, for instance, you can use:

 
String uservalue = This. Request. Form ["user"];

 

Q: If the name of element duplicated, such as two of checkbox are named chk, how to separate one from another?

A: In server-side, they be separated by comma (,). If you extract the value of checkbox By follow CSHARP statement:

 
String chk = This. Request. Form ["Chk"];

You'll get value as: checkboxa, checkboxb

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.