Method properties for HTML <form> tags (20161028)

Source: Internet
Author: User
Tags http post

Method properties for HTML <form> tags

HTML <form> Tags

Instance

In the following example, the form data is appended to the URL via the method attribute:

<form action= "form_action.asp" method= "Get" >

<p>first Name: <input type= "text" name= "FName"/></p>

<p>last Name: <input type= "text" name= "lname"/></p>

<input type= "Submit" value= "Submit"/>

</form>

Try it yourself.

Definition and usage

The method property specifies how the form data is sent (the form data is sent to the page specified by the Action property).

The form data can be sent as a URL variable (method= "get") or as an HTTP post (method= "POST").

Method Properties

The browser uses the method property setting to route data from the form to the server for processing. There are two methods: the POST method and the GET method.

If the POST method is used, the browser will send the data in the following two steps. First, the browser will contact the form processing server specified in the Action property, and once the connection is established, the browser will send the data to the server in a segmented transfer.

On the server side, once the POST-style application starts executing, the parameters should be read from a flag location, and once the parameters are read, the parameters must be decoded before the application can use the form values. User-specific servers explicitly specify how the application should accept these parameters.

Another scenario is when a GET method is used, where the browser establishes a connection to the form processing server and then sends all the form data directly in a single transport step: The browser will attach the data directly to the action URL of the form. The two are separated by a question mark.

General browsers can transmit form information through either of these methods, whereas some servers only accept data provided by one of these methods. You can specify in the method property of the <form> tag how the form processing server will handle the data using the method to make the POST or GET.

POST or GET?

If the form processing server supports both the POST method and the GET method, which method do you choose? Here are some of the rules about this:

    • If you want the best form transfer performance, you can use the Get method to send small forms with only a few short fields.
    • Some server operating systems limit the number and length of command-line arguments that can be passed to an application immediately, in which case the POST method should be used for forms that have many fields or long text fields.
    • If you are inexperienced in writing server-side form-processing applications, you should choose the GET method. If you use the POST method, you will need to do some extra work on the read and Decode methods, which may not be very difficult, but you may not be willing to deal with these problems.
    • If security is a problem, then we recommend that you use the POST method. The GET method places form parameters directly in the URL of the application, so that network snooping can easily capture them and extract them from the server's log file. If the parameter contains sensitive information such as a credit card account, it can unknowingly compromise the user's security. There is no security vulnerability in the POST application, and at least an encrypted method can be used when transferring parameters as separate transactions to the server for processing.
    • If you want to invoke the server-side application outside of the form, and include the procedure to pass parameters to it, take the GET method, because it allows parameters such as forms to be included as part of the URL. On the other hand, applications that use the post style want to have an additional transfer process from the browser after the URL, where the transferred content cannot be used as the content of the traditional <a> tag.

Explicitly passing parameters

Some of the previous recommendations can also be used as a definite explanation for choosing this approach. Suppose you have a very simple form that contains only the two parameters, X and Y. When the values of these elements are encoded, they are in the form of the following:

x=28&y=66

If the form is Method=get, then the URL used to reference the server-side application will look like this:

http://www.example.com/example/program?x=28&y=66

At any time, we can create a traditional <a> tag that calls the form with the required parameter values in the form of the following:

<a href= "http://www.example.com/example/program?x=28&y=66" >

The only problem is that the & symbol used to separate the arguments is also the caret in the character entity. If a & symbol is placed in the href attribute of the <a> tag, the browser replaces the characters that follow it with the corresponding character entity.

In order to prevent this, we must replace the & symbol with its physical counterpart, that is, "& #38;" or "&amp;". After the substitution, the non-form example of the reference server application above will look like this:

<a href= "http://www.example.com/example/program?x=28&amp;y=66" >

Since it is still not possible to use the & symbol in the URL, and it may cause confusion in the future, we encourage the server setting to accept the semicolon as the parameter delimiter at last. You can also check your server documentation to see if the server supports this feature.

Grammar

<form target= "value" >

Property value

Value

Describe

_blank

Opens in a new window.

_self

Default. Open in the same frame.

_parent

Opens in the parent frameset.

_top

Opens in the entire window.

FrameName

Opens in the specified frame.

HTML <form> Tags

Method Properties for HTML <form> tags (20161028)

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.