首页 > 其他 > 详细

使用表单

时间:2015-02-12 13:48:38      阅读:249      评论:0      收藏:0      [点我收藏+]

1.1使用一个简单的输入表单

表单页

<!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访问表单输入的数据

1.2使用数组访问表单

表单页面

<!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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!