标签:
表单页
<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> </head> <body> <form method="post" action="send.php"> <input type="text" name="user" /> <textarea name="message"> </textarea> <button type="submit">发送消息</button> </form> </body> </html>
send.php
<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> </head> <body> <?php echo $_POST[‘user‘].":".$_POST[‘message‘]; ?> </body> </html>
使用超全局变量$_POST访问表单输入的数据
表单页面
<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> </head> <body> <form method="post" action="send.php"> 1. <input type="checkbox" name="products[]" value="yellow"/> <br />2. <input type="checkbox" name="products[]" value="red"/> <br />3. <input type="checkbox" name="products[]" value="blue"/> <br /> <button type="submit">提交</button> </form> </body> </html>
send.php
<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> </head> <body> <?php //empty判断是否为空 if (!empty($_POST[‘products‘])){ echo "<ul>"; //foreach遍历数组 foreach($_POST[‘products‘] as $value) { echo "<li>".$value."</li>"; } echo "</ul>"; }else { echo "没有选择"; } ?> </body> </html>
将同类的输入存放到数组中,只需要在变量名后面加个[]就可以。如上述实例中每个input的name属性都是products[];
标签:
原文地址:http://www.cnblogs.com/winderby/p/4287786.html