<?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { echo '<script>confirm("确认提交吗?");</script>'; } ?> <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <link rel="stylesheet" href="lib/dist/css/bootstrap.css"> <script src="lib/jquery-3.2.1.js"></script> <script src="lib/dist/js/bootstrap.js"></script> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <div class="container"> <div class="row"> <div class="col-md-12 text-center"> <h1>用户注册</h1> </div> </div> <div class="row"> <div class="col-md-12"> <form class="form-horizontal" method="post"> <div class="form-group"> <label for="inputEmail3" class="col-sm-2 control-label">用户名</label> <div class="col-sm-10"> <input type="text" name="name" value="<?php echo (isset($_POST['name'])) ? $_POST['name']:'' ?>"><br> </div> </div> <div class="form-group"> <label for="inputPassword3" class="col-sm-2 control-label">密码</label> <div class="col-sm-10"> <input type="password" name="password" value="<?php echo (isset($_POST['password'])) ? $_POST['password']:'' ?>"> </div> </div> <div class="form-group"> <label for="inputPassword3" class="col-sm-2 control-label">性别</label> <div class="col-sm-10"> <input type="radio" name="gender" value="male" <?php echo (isset($_POST['gender']) && ($_POST['gender']=='male')) ? 'checked' :'' ?> >男 <input type="radio" name="gender" value="female" <?php echo (isset($_POST['gender']) && ($_POST['gender']=='female')) ? 'checked' :'' ?>>女 </div> </div> <div class="form-group"> <label for="inputPassword3" class="col-sm-2 control-label">学历</label> <div class="col-sm-10"> <select name=""> <option value="bk" <?php echo (isset($_POST['degree']) && ($_POST['degree']=='bk')) ? 'selected' :'' ?>>本科</option> <option value="yjs" <?php echo (isset($_POST['degree']) && ($_POST['degree']=='yjs')) ? 'selected' :'' ?>>研究生</option> <option value="bs" <?php echo (isset($_POST['degree']) && ($_POST['degree']=='bs')) ? 'selected' :'' ?>>博士</option> </select> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <button type="submit" class="btn btn-default">提交</button> </div> </div> </form> </div> </div> </div> </body> </html>
备注:
<?php echo (isset($_POST['degree']) && ($_POST['degree']=='bk')) ? 'selected' :'' ?>
<?php echo (isset($_POST['gender']) && ($_POST['gender']=='male')) ? 'checked' :'' ?>
<?php echo (isset($_POST['name'])) ? $_POST['name']:'' ?>