Blogger Information
Blog 34
fans 0
comment 0
visits 33730
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php之实现黏性表单
Serendipity-Ling
Original
729 people have browsed it

提交前QQ图片20171229114030.png

提交后QQ图片20171229114101.png

<?php
$Name=isset($_POST['name'])?$_POST['name']:null;

$Psd=isset($_POST['psd'])?$_POST['psd']:null;
switch (@$_POST['hobby']) {
 case '1';
 $Hobby='技术宅';
 break;
 case '2';
 $Hobby='口才王';
 break;
 case '3';
 $Hobby='颜值帝';
};
$Gender=isset($_POST['gender'])?$_POST['gender']:null;

?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <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>粘性表单</title>
    <style>
        .main {
            margin-top: 200px;
            text-align: center;
        }
        .input {
            width: 175px;
        }
        .btn {
            width: 50px;
            height: 21px;
            border-radius: 5px;
            background-color: skyblue;
        }
    </style>
</head>
<body>

      <div class="main">
        <h2>注册<small style="color: skyblue">Login</small></h2>
          <form action="" method="post">
              <p>
                  <label>用&nbsp;&nbsp;户:&nbsp;&nbsp;<input type="text" name="name" class="input" value="<?php echo $Name ?>"></label>

              </p>
              <p><span id="ero1" style="color: red">
                      <?php
                      if (empty($Name)){
 echo '<script>
                                 var ero1 = document.getElementsByTagName("span")[0];
 ero1.innerHTML="请输入用户名"
                                </script>';
                      }
 ?>
 </span></p>
              <p><label>密&nbsp;&nbsp;码:&nbsp;&nbsp;<input type="password" name="psd" class="input" required value="<?php echo $Psd ?>"></label></p>
              <p>性&nbsp;&nbsp;别:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 <label><input type="radio" name="gender" value="male"  class="gender" <?php echo $Gender='male'?'checked':null; ?> >男</label>
                  &nbsp;&nbsp;&nbsp;&nbsp;
 <label><input type="radio" name="gender" value="female" class="gender" <?php echo $Gender='female'?'checked':null; ?> >女</label>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 <p><label>身&nbsp;&nbsp;份:&nbsp;&nbsp;
 <select name="hobby" class="input">
                      <option value="1">技术宅</option>
                      <option value="2" <?php echo @$Hobby=='口才王'?'selected':null; ?> >口才王</option>
                      <option value="3" <?php echo @$Hobby=='颜值帝'?'selected':null; ?> >颜值帝</option>
                  </select>
                  </label>
              </p>
              <p>
                  <input type="submit" name="submit" value="提交" class="btn">
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 <button class="btn">重置</button>
              </p>
          </form>
      </div>
</body>
<script>
    var Reset = document.getElementsByClassName('btn')[1];
    //重置按钮点击事件
 Reset.onclick = function () {
        //直接获取了我用户名的input里的value属性,然后直接给了空值
 document.getElementsByTagName('input')[0].value='';
        document.getElementsByTagName('input')[1].value='';
        //跟js结合的话最好使用button
 }
</script>
</html>

学习感想:

  1. 其中运用了@符过滤了报错信息,@符真是让人又爱又恨,有时候总会出现关于变量undefined的报错,但是加上@后就不会将改报错信息展现出来,但其实并没真正解决问题。

  2. 关于与js结合时,尽量选用button按钮来进行事件绑定,简单直接

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post