When the method of the HTML form (HTML form) is GET, $_get is used to obtain the data for the HTML form.
When the method of an HTML form (HTML form) is post, $_post is used to get the data for the HTML form.
The difference between get and post for HTML form, see the difference between get and post for HTML form.
Gets the HTML form (HTML form) text input box (input type= "text") data
The following is an HTML file that contains an HTML Form that is used primarily for users to enter user names.
Copy Code code as follows:
<body>
<form action = "post.php" method = "POST" >
Name: <input type= "text" name= "username"/>
<input type = "Submit" value= "OK"/>
</form>
</body>
When you enter the name in the text box of the HTML Form, such as "Jacky", then the mouse clicks OK button, will jump to post.php, display output is you are Jacky. Post.php's source code is as follows:
Copy Code code as follows:
<body>
You are <?php echo $_post["username"]?>.
</body>
You can get the data for the form control by taking the name value of the form control.
For example, "username" is the name value of the form control text input box,
<input type= "text" name= "username"/>
Use $_post["username"] to get the data for the text entry box.
<?php echo $_post["username"]?>
Get HTML form (HTML form) radio box (input type= "Radio") data
Take the name value of the selected box in the table, and you can get the value of the table-only selection box.
Below is an HTML file with a table-only selection box, with the following code:
Copy Code code as follows:
<body>
<form action = "radiopost.php" method = "POST" >
<input type= "Radio" name= "fruit" value = "Apple" >apple</input><br/>
<input type= "Radio" name= "fruit" value = "Orange" >orange</input><br/>
<input type= "Radio" name= "fruit" value = "Mango" >mango</input><br/>
<input type= "Submit" value= "OK" >
</form>
</body>
In the HTML file, select a random item, such as "Orange", and then click the button OK, the browser will jump to the radiopost.php,radiopost.php output is Orange. Radiopost.php's source code is as follows:
Copy Code code as follows:
<body>
<?php echo $_post["Fruit"]?>
</body>
The fruit in $_post["fruit" is the name value of the table-only selection box.
Get the HTML form (HTML form) check box (input type= "checkbox") data
Users can select multiple values through the HTML Form checkbox, so $_post gets more than one value, which is the array of numbers.
When you write the name value of the HTML Form check box, note that the name value is finally added [].
The following example, Name= "fruit[]":
Copy Code code as follows:
<body>
<form action = "checkboxpost.php" method = "POST" >
<input type= "checkbox" Name= "fruit[]" value = "Apple" >apple</input><br/>
<input type= "checkbox" Name= "fruit[]" value = "Orange" >orange</input><br/>
<input type= "checkbox" Name= "fruit[]" value = "Mango" >mango</input><br/>
<input type= "Submit" value= "OK" >
</form>
</body>
Checkboxpost.php's source code is as follows:
Copy Code code as follows:
<body>
<?php
echo count ($_post["fruit"]), "<br/>";
foreach ($_post["fruit"] as $value)
{echo $value, "<br/>";
}
?>
</body>
If you choose orange and Mango, and click the OK button, the browser will jump to checkboxpost.php, first use the Count function to get the array $_post["fruit" the number of elements, if the user selected 2, the result is 2, and then use The Foreach loop outputs the value of each element of the $_post["fruit", which is the value of the user's selected item, Orange and Mango.