


Understand the GET and POST submission methods in the form tag in ten minutes
This article brings you relevant knowledge and comparison of the two submission methods of get and post in the form tag. The function of the form form is to collect the content in the tag,
In the middle, visitors can add text, selections, or some control modules, etc. Then these contents will be sent to the server. I hope it will be helpful to everyone.GET and POST in the form tag
In HTML, the function of the form form is to collect the content in the tag,< ;form>...
In the middle, the visitor can add text, selections, or some control modules, etc. Then these contents will be sent to the server.
A form must specify two things:
- The method parameter of form is used to set the submission method of the form, and POST is used by default.
- action is used for Set the submission URL of the form. If you do not write it or keep an empty string, the current URL will be used.
①Example of form submission using post method:
Below Example implementation process:
When we access this interface for the first time, it is the GET method (accessing a URL in the browser is a GET method, no need to explain). Observing the view function, we can see that it renders the form to the user. template page.
When we enter data in the input box and click submit, a POST method will be sent, so that according to the view function, the data entered in the input box will be printed on the console.
Note:
- The post submission method will not display parameters in the URL;
- You can obtain the submitted information through request.POST.get data.
②Example of form submission using get method:
The following example implementation process:
When we access this interface for the first time, it is the GET method (accessing a URL in the browser is a GET method, no explanation is needed). Observing the view function, we can see that it renders to the user with The form template page.
When we enter data in the input box and click submit, the GET method will be sent (because we set the POST submission method in the form form), so that according to the view function, the input box input will be printed on the console The data.
(Because of our settings, clicking the submit button in the template is a GET submission, and the values of a and b submitted by the form form can be printed on the corresponding terminal.)
Note:
- getThe submitted parameters will be displayed in the url;
- You can obtain the submitted parameters through the request.GET.get method.
The attributes GET and POST of the request object are both QueryDict type objects; Different from python dictionaries, QueryDict type objects are used to handle situations where the same key has multiple values.
- Method get():
- Get the value according to the key, you can only get one value of the key
If a key has multiple values at the same time, get the last value (because Covered!)
Method getlist(): - Get the value according to the key and return the value of the key in a list
You can get multiple values of a key
For example: How does the backend get the options selected by the user in the multi-select box - use the getlist method!
④Attributes of GET and POST objects in request:
First: GET attribute!
- Object of QueryDict type
- Contains all parameters of the get request method
- Corresponds to the parameters in the url request address, located after ?
- The format of the parameters is a key-value pair, such as key1=value1
- Use & to connect multiple parameters, such as key1=value1&key2=value2
The second one: POST attribute!
- QueryDict type object
- Contains all parameters of the post request method
- Corresponds to the controls in the form form
- The controls in the form must have name attribute, then the value of the name attribute is the key, and the value of the value attribute is the value, forming a key-value pair submission
- For the checkbox control, the name attribute is also a group, and will be submitted when the control is selected. There is One-click multi-value situation.
Small extension:
Construct a GET request-as long as we click the 'click' button, we will find that the function is the same as "②form form usage" "get method" has the same effect. We can also print the values of a and b on the backend (you can also see it by observing the URL link in the browser!), indicating that the data submission is successful!
⑤ Summary of GET and POST request methods:
- GET: GET, as its name suggests, obtains data from the server and does not change the server. The status and data are sent to the server carrying parameters in the URL.
- POST sends a certain amount of data to the server, usually changing the server's data.
- The parameters of the POST method cannot be seen in the URL. They are passed to the server through the body parameters. Therefore, compared with the GET method, you can directly see the passed parameters in the URL, which is safer. Of course, it is also It cannot be simply judged that the POST method is more secure than the GET method. To keep the website safe, more security processing needs to be done.
Recommended tutorial: "html video tutorial"
The above is the detailed content of Understand the GET and POST submission methods in the form tag in ten minutes. For more information, please follow other related articles on the PHP Chinese website!

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.

HTMLisaspecifictypeofcodefocusedonstructuringwebcontent,while"code"broadlyincludeslanguageslikeJavaScriptandPythonforfunctionality.1)HTMLdefineswebpagestructureusingtags.2)"Code"encompassesawiderrangeoflanguagesforlogicandinteract

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver Mac version
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.