php实现数据粘性例子

php实现表单粘性例子

 

在填表单的时候,有时候会出现表单未填完就提交的情况,这时候若是想要回到原来的表单页面,一般之前填的内容都会消失掉。

故使用PHP实现回到原来表单但是填写数据不消失,代码?如下

 1<?php
    if (isset($_POST)) {
        $name = $_POST['username'] ?? NULL;
        $text = $_POST['text'] ?? NULL;
        if (isset($_POST['like'])) {
            foreach ($_POST['like'] as $key => $value)
                $check[$value] = "checked";
        }
    }
?>
<!DOCTYPE html>
<html>
<head>
    <title>FORM</title>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="http://cdn.amazeui.org/amazeui/2.7.2/css/amazeui.min.css">
</head>
<body>
    <div class="am-container">
    <form class="am-form" method="post" action="index.php">
        <legend>黏性表单</legend>
        <div class="am-form-group">
            <label for="doc-ipt-name">用户名</label>
            <input type="text" placeholder="给个名字吧" name="username" value=<?php if echo $name ?? NULL;?>>
        </div>
        <div class="am-form-group">
            <label for="doc-select-2">喜欢的编程语言</label>
            <label class="am-checkbox-inline">
                <input type="checkbox" value="php" name="like[]" <?php echo $check['php'] ?? NULL;?>> PHP
            </label>
            <label class="am-checkbox-inline">
                <input type="checkbox" value="python" name="like[]" <?php echo $check['python'] ?? NULL;?>> PYTHON
            </label>
            <label class="am-checkbox-inline">
                <input type="checkbox" value="java" name="like[]" <?php echo $check['java'] ?? NULL;?>> JAVA
            </label>
            <label class="am-checkbox-inline">
                <input type="checkbox" value="c++" name="like[]" <?php echo $check['c++'] ?? NULL;?>> C++
            </label>
        </div>
        <div class="am-form-group">
            <label for="doc-ta-1">有什么想说的</label>
            <textarea rows="5" id="doc-ta-1" name="text"><?php echo $text ?? NULL; ?></textarea>
        </div>
        <button type="submit" class="am-btn am-btn-default">提交</button>
    </form>
</div>
</body>
</html>

 

 

转载于:https://www.cnblogs.com/huangjiaming/p/5693716.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值