PHP jQuery表单,带验证具体实现方法

Email检测,密码重复检测,可以用于表单发送的各种环境,例如发送反馈,注册帐号

PHP jQuery表单,带验证具体实现方法

复制代码 代码如下:


<div> 
        <?if( isset($_POST['send']) && (!validateName($_POST['name']) || !validateEmail($_POST['email']) || !validatePasswords($_POST['pass1'], $_POST['pass2']) || !validateMessage($_POST['message']) ) ):?> 
                <div> 
                    <ul> 
                        <?if(!validateName($_POST['name'])):?> 
                            <li><strong>Invalid Name:</strong> We want names with more than 3 letters!</li> 
                        <?endif?> 
                        <?if(!validateEmail($_POST['email'])):?> 
                            <li><strong>Invalid E-mail:</strong> Stop cowboy! Type a valid e-mail please :P</li> 
                        <?endif?> 
                        <?if(!validatePasswords($_POST['pass1'], $_POST['pass2'])):?> 
                            <li><strong>Passwords are invalid:</strong> Passwords doesn't match or are invalid!</li> 
                        <?endif?> 
                        <?if(!validateMessage($_POST['message'])):?> 
                            <li><strong>Ivalid message:</strong> Type a message with at least with 10 letters</li> 
                        <?endif?> 
                    </ul> 
                </div> 
            <?elseif(isset($_POST['send'])):?> 
                <div> 
                    <ul> 
                        <li><strong>Congratulations!</strong> All fields are OK ;)</li> 
                    </ul> 
                </div> 
        <?endif?> 

        <form method="post" action=""> 
            <div> 
                <label for="name">Name</label> 
                <input type="text" /> 
                <span>What's your name?</span> 
            </div> 
            <div> 
                <label for="email">E-mail</label> 
                <input type="text" /> 
                <span>Valid E-mail please, you will need it to log in!</span> 
            </div> 
            <div> 
                <label for="pass1">Password</label> 
                <input type="password" /> 
                <span>At least 5 characters: letters, numbers and '_'</span> 
            </div> 
            <div> 
                <label for="pass2">Confirm Password</label> 
                <input type="password" /> 
                <span>Confirm password</span> 
            </div> 
            <div> 
                <label for="message">Message</label> 
                <textarea cols="" rows=""></textarea> 
            </div> 
            <div> 
                <input type="submit" value="Send" /> 
            </div> 
        </form> 
    </div> 

validation.php

复制代码 代码如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/995d05dc59b1e37433f70a10b8535aca.html