TP8笔记250312


5.14 消息提示:_messages.html ?php use thinkfacadeSession; foreach ([ success , info , danger , warning ] as $msg): ? ?php if(Session::has($msg)): ? div class=text-center alert a...

5.14 消息提示:_messages.html

<?php use think\facade\Session;

foreach (['success','info','danger','warning'] as $msg): ?>
    <?php if(Session::has($msg)): ?>
    <div class="text-center alert alert-<?php echo $msg; ?>" role = "alert">
        <i class="fa fa-bullhorn"></i> <?php echo Session::get($msg); ?>
    </div>
    <?php endif;?>
<?php endforeach;?>

需要在User.php重定向中加入读取闪存代码with

return redirect((string) url('User/read',['id' => $user->id]))->with('success','恭喜您,注册成功!');

同时还要在default.html父html中引入:

{include file="shared/_messages" /}

5.15 HTML5自带校验

<div class="card-body">
                {include file="shared/_errors" /}
                <form method="post" action="{:url('User/save')}">
<!--                    <input type="hidden" name="__token__" value="{:token()}" />-->
                    {:token_field()}
                    <div class="mb-3">
                        <label for="name" class="form-label">用户名:</label>
                        <input type="text" required maxlength="255" class="form-control" placeholder="请输入用户名" id="name" name="name">
                    </div>
                    <div class="mb-3">
                        <label for="email" class="form-label">电子邮箱:</label>
                        <input type="email" required maxlength="255" class="form-control" placeholder="请输入您的电子邮箱" id="email" name="email">
                    </div>
                    <div class="mb-3">
                        <label for="password" class="form-label">密码:</label>
                        <input type="password" required minlength="6" maxlength="255" class="form-control" placeholder="请输入您的密码" id="password" name="password">
                    </div>
                    <div class="mb-3">
                        <label for="password_confirm" class="form-label">密码确认:</label>
                        <input type="password" required minlength="6" maxlength="255" class="form-control" placeholder="请再次输入您的密码确认" id="password_confirm" name="password_confirm">
                    </div>
                    <div class="d-flex justify-content-center">
                        <button type="submit" class="btn btn-primary">注册</button>
                    </div>
                </form>
            </div>

前端拦截了大部分,大大减轻服务器负担。


推荐阅读:

收藏

扫描二维码,在手机上阅读

TP8笔记250314

TP8笔记250311

评 论
请登录后再评论