Verification information for PHP development registration page

Let’s take a look first, our registration page

reg.jpg


# From the picture above we can see that if the user’s username, password and verification code are not filled in, the user will be registered. , we do not allow it, these three items need to be verified, and the user’s password and confirmation password are entered twice differently, we do not allow it, this item is also our verification scope,


First we need to add JS events to our <form> form

<form action="" method="post"  name="myform" onsubmit=" return checkinput();" >

So that if our user submits the form, the js event will be triggered. Here is our JS judgment

<script type="text/javascript">
    function checkinput()
    {
        if(myform.name.value=="")
        {
            alert("请输入用户名");
            myform.name.focus();
            return false;
        }
        if (myform.pwd.value=="")
        {
            alert("请输入密码");
            myform.pwd.focus();
            return false;
        }
        if(myform.pwd.value != myform.pwdconfirm.value){
            alert("你输入的两次密码不一致,请重新输入!");
            myform.pwd.focus();
            return false;
        }
        if (myform.yzm.value=="")
        {
            alert("请输入验证码");
            myform.yzm.focus();
            return false;
        }
    }
</script>

Submit when the information filled in by the user is incorrect, our JS event is triggered, and relevant prompt information is given to the user


The complete code for verification is as follows

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>PHP中文网</title>
    <script type="text/javascript">
        function checkinput()
        {
            if(myform.name.value=="")
            {
                alert("请输入用户名");
                myform.name.focus();
                return false;
            }
            if (myform.pwd.value=="")
            {
                alert("请输入密码");
                myform.pwd.focus();
                return false;
            }
            if(myform.pwd.value != myform.pwdconfirm.value){
                alert("你输入的两次密码不一致,请重新输入!");
                myform.pwd.focus();
                return false;
            }
            if (myform.yzm.value=="")
            {
                alert("请输入验证码");
                myform.yzm.focus();
                return false;
            }
        }
    </script>
</head>
<body>
<form action="" method="post"  name="myform" onsubmit=" return checkinput();" >
    <div class="container">
        <div class="right">
            <h2>用户注册</h2>
            <p>用 户 名:<input type="text" name="name" id="name"></p>
            <p>密  码: <input type="password" name="pwd" id="pwd"></p>
            <p>确认密码: <input type="password" name="pwdconfirm" id="pwdconfirm"></p>
            <p>验 证 码:<input type="text" name="yzm" id="yzm">
                <img src="yanzhengma.php" onClick="this.src='yanzhengma.php?nocache='+Math.random()" style="cursor:hand"></p>
            <p><button type="submit" value="注册" >立即注册</button></p>
        </div>
    </div>
</form>
</body>
</html>



Continuing Learning
||
<!doctype html> <html> <head> <meta charset="utf-8"> <title>PHP中文网</title> <script type="text/javascript"> function checkinput() { if(myform.name.value=="") { alert("请输入用户名"); myform.name.focus(); return false; } if (myform.pwd.value=="") { alert("请输入密码"); myform.pwd.focus(); return false; } if(myform.pwd.value != myform.pwdconfirm.value){ alert("你输入的两次密码不一致,请重新输入!"); myform.pwd.focus(); return false; } if (myform.yzm.value=="") { alert("请输入验证码"); myform.yzm.focus(); return false; } } </script> </head> <body> <form action="" method="post" name="myform" onsubmit=" return checkinput();" > <div class="container"> <div class="right"> <h2>用户注册</h2> <p>用 户 名:<input type="text" name="name" id="name"></p> <p>密  码: <input type="password" name="pwd" id="pwd"></p> <p>确认密码: <input type="password" name="pwdconfirm" id="pwdconfirm"></p> <p>验 证 码:<input type="text" name="yzm" id="yzm"> <img src="yanzhengma.php" onClick="this.src='yanzhengma.php?nocache='+Math.random()" style="cursor:hand"></p> <p><button type="submit" value="注册" >立即注册</button></p> </div> </div> </form> </body> </html>
submitReset Code