Home >Backend Development >PHP Tutorial >How to get form content in php

How to get form content in php

一个新手
一个新手Original
2017-09-09 08:59:161944browse

1: Briefly introduce how to obtain it

#When php accepts information submitted through an HTML form, it will save the submitted data in a global array , we can call the system-specific automatic global variable array to obtain these values.

Two: Commonly used automatic global variables are:

$_GET;
$_POST;
$_REQUEST
其中前两个是经常用的。
他们是通过:from标签中的method 里面传的方式  如果是get就用$_GET属性  如果是post就用 $_POST;
例子:
<form method="post" action="index.php">帐号:<input type = "text" name=login><br>
</form>
echo("你的帐号是:" . $_POST[&#39;login&#39;]);  
这里我们用的post方式传输的所以就要用$_POST;

Three: Not much to say Example:

## html code:

<html>
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf8">  
</head> 
<body>  
<form action="send_simpleForm.php" method="POST">name:<input type="text" name="username"><br>
<select name="products[]" size=6 multiple> 
<option value="c++">c++</option> 
<option value="c#">c#</option>
  <option value="php">php</option>
<option value="Python">Python</option> 
<option value="lua">lua</option>
  <option value="JavaScript">JavaScript</option> 
</select><br />
  Message:<br>
 <textarea name="message" rows="5" cols="40">
</textarea><br> 
<input type="submit" value="ok">  
</form>  
</body>
</html>
php code:
<?php  
  
header("Content-Type: text/html; charset=UTF-8");  
  
if (isset($_POST["username"]))  
{  
    echo "输入的名户名为:" . $_POST["username"] . "<br>";  
}  
  
if (isset($_POST["products"]))  
{  
    if (is_array($_POST["products"]) && !empty($_POST["products"]))  
    {  
        echo "选择的科目为:" . "<br>";  
        foreach ($_POST["products"] as  $value ) {  
            echo  "$value <br />";  
        }  
        echo "选择的个数为:" . count($_POST["products"]) . "<br>";  
    }  
}  
  
if (isset($_POST["message"]))  
{  
    echo "输入的消息为:" . $_POST["message"] . "<br>";  
}  
  
//表单如果以POST提交,那么获取内容是就用$_POST["control_name"];  
//表单如果以GET提交,那么获取内容就用$_GET["control_name"];  
    
 ?>

Four: Summary:

PHP gets the summary of each value in the form :Form submission method
1. GET method
Function: Get the data submitted by get method
Format:

$_GET[“formelement”]

2. POST method Function: Get the data submitted by post method
Format:

$_POST[“formelement”]

3. REQUEST method Function: Get any Data submitted via method
Format:

$_REQUEST[“formelement”]
复选框、列表框(名称采用数组形式如:"select[]",在获取其值的时候直接使用$_POST["select"]即可)

The above is the detailed content of How to get form content in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn