php 超全局变量 $_get 和 $_post 用于收集表单数据(form-data)。
php - 一个简单的 html 表单
下面的例子显示了一个简单的 html 表单,它包含两个输入字段和一个提交按钮:
实例
<html><body><form action="welcome.php" method="post">name: <input type="text" name="name"><br>e-mail: <input type="text" name="email"><br><input type="submit"></form></body></html>
当用户填写此表单并点击提交按钮后,表单数据会发送到名为 "welcome.php" 的 php 文件供处理。表单数据是通过 http post 方法发送的。
如需显示出被提交的数据,您可以简单地输出(echo)所有变量。"welcome.php" 文件是这样的:
<html><body>welcome <?php echo $_post["name"]; ?><br>your email address is: <?php echo $_post["email"]; ?></body></html>
输出:
welcome billyour email address is bill.gates@example.com
使用 http get 方法也能得到相同的结果:
实例
<html><body><form action="welcome_get.php" method="get">name: <input type="text" name="name"><br>e-mail: <input type="text" name="email"><br><input type="submit"></form></body></html>
"welcome_get.php" 是这样的:
<html><body>welcome <?php echo $_get["name"]; ?><br>your email address is: <?php echo $_get["email"]; ?></body></html>
上面的代码很简单。不过,最重要的内容被漏掉了。您需要对表单数据进行验证,以防止脚本出现漏洞。
注意:在处理 php 表单时请关注安全!
本页未包含任何表单验证程序,它只向我们展示如何发送并接收表单数据。
更多php相关知识,请访问!
以上就是php表单是干嘛的的详细内容。
