The form is mainly responsible for data collection in the webpage, and the data is transmitted as a whole, which greatly improves the efficiency of data submission to the server.
Form three basic components:
Form Tag: contains the URL of the CGI program used to process form data and the method for submitting data to the server.
Form field: contains the text box, password box, hidden field, multi-line text box, check box, single choice, drop-down selection box, and file upload box.
Form button: includes the submit button, reset button, and general button. It is used to send data to the CGI script on the server or cancel the input, you can also use the form button to control the processing of other defined scripts.
Form format:
<Form name = "form name" method = "GET | Post" Action = "url">... </form>
Form data can be submitted to the server in two ways: Get and post.
Request. form ["username"]. tostring (); or: request. form. get ["username"]. tostring (); get method receiving: request ["username"]. tostring ();
(1) get is to add the parameter data queue to the URL referred to by the Action attribute of the submission form. The values correspond to each field in the form one by one and can be seen in the URL. Post uses the http post mechanism to place fields and content in the form in HTML. The header is sent together to the URL address referred to by the Action attribute. You cannot see this process.
(2) For the get method, the server uses request. querystring to obtain the value of the variable. For the POST method, the server uses request. Form to obtain the submitted data.
(3) The data volume transmitted by get is small and cannot exceed 2 kb. The amount of data transmitted by post is large, which is generally not restricted by default. Theoretically, the maximum size of IIS4 is 80 KB, and that of iis5 is 100kb.
(4) Low get security and high post security.
Post and get contact:
Get attaches form data to the URL address of the Request page. The get method is used to transmit a small amount of data. The URL length is limited to 8192 characters. If the sent data volume is too large, the data will be truncated, resulting in unexpected processing results.
Post embeds form data in HTTP requests. The post method can be used to send a large amount of data, and the post method is safer than the get Method for sending confidential information such as username, password, and credit card.
Note
In general, try to avoid using the get method to submit a form because it may cause security problems. For example, if you use the get method in the login form, the user name and password entered by the user will be exposed in the address bar. However, in the paging program, the get method is better than the POST method. Attribute explanation of the form used in this example (see Section 4 of ASP): Get adds the parameter to the address specified by the Action attribute and opens it as an anchor.
Post processes sent data through http post.
Form data set
Pipeline contains a form. The method for transmitting data from a form is post, and the form is submitted to do. aspx in the same directory. The form.htm code is as follows:
<HTML>
In do. aspx, request. Form ["mingzi"] is used to obtain the user input name. The do. aspx code is as follows:
Private void page_load (Object o, eventargs E)
// The form data is displayed after the page is loaded.
{String strmessage = "Your name is:"; // define the string variable and assign the initial value strmessage + = request. form ["mingzi"]; // receives the form data string to the variable response. write (strmessage); // output variable}Querystring data set
You can use the querystringset to obtain the table data transmitted through getaskfrom the client. If you change the value of the Form Method attribute in form.htm from post to get, you need to obtain the input name in do. aspx through request. querystring ["mingzi. Because the get method has certain restrictions on data transmission and is not secure, the form generally does not use the get method.
Private void page_load (Object sender, system. eventargs e) {If (request. querystring ["mingzi"]. tostring ()! = "") Response. Write ("Your name is:" + request. querystring ["mingzi"]. tostring ());}
In web application development, querystring is often used to obtain the value of the variable in the URL query string, which is the same as transmitting form data using the get method. With the deepening of practice, we will gradually deepen our understanding!