0

我有一个注册页面

<form class="register" action="regist.php" method="post" >
                    <h3>Register</h3>
                    <div class="column">
                        <div>
                            <label>First Name:</label>
                            <input type="text" name="f_name"/>
                            <span ></span>
                        </div>
                        <div>
                            <label>Last Name:</label>
                            <input type="text" name="l_name"/>
                            <span class="error">This is an error</span>
                        </div>
                        <div>
                            <label>mobile:</label>
                            <input type="text" name="mobile"/>
                            <span class="error">This is an error</span>
                        </div>
                    </div>
                    <div class="column">
                        <div>
                            <label>Username:</label>
                            <input type="text"name="user"/>
                            <span >This is an error</span>
                        </div>
                        <div>
                            <label>Email:</label>
                            <input type="text" name="email"/>
                            <span class="error">This is an error</span>
                        </div>
                        <div>
                            <label>Password:</label>
                            <input type="password" name="pass"/>
                            <span class="error">This is an error</span>
                        </div>
                    </div>
                    <div class="bottom">
                        <div class="remember">

                        </div>
                        <input type="submit" value="Register" name="submet" />
                        <a href="index.html" rel="login" class="linkform">You have an account already? Log in here</a>
                        <div class="clear"></div>
                    </div>
                </form>

使用 jquery bpopup

   $(function() {

        // Binding a click event
        // From jQuery v.1.7.0 use .on() instead of .bind()
        $('#my-button').bind('click', function(e) {

            // Prevents the default action to be triggered. 
            e.preventDefault();

            // Triggering bPopup when click event is fired
            $('#element_to_pop_up').bPopup();

        });

    }

所以当点击注册时,表单会弹出一切正常问题是我无法对表单进行验证,因为当我在填写表单后单击注册时,弹出窗口会消失,所以我无法在同一个表单上进行验证

我尝试 1 制作另一个显示错误的弹出窗口,但数据不会传递到新的弹出窗口 2 进行操作$_SERVER['self_request'] 有人可以帮我解决这个问题吗 请我为我的大学有一个项目,我需要在 3 天内完成

我需要的是在将表单发送到 MySQL 脚本之前验证同一页面或另一个弹出窗口中的表单

4

1 回答 1

0

制作一个使用 GET 函数获取信息的 php 页面(此处称为 validation.php)...

然后在输入字段上设置一些ID...

然后做一个这样的函数:

function checkAll(){
    var firstName = document.getElementById("f_name").value();
    var lastName = document.getElementById("l_name").value();
    $.get( "validation.php?f_name=" + firstName + "&l_name=" + lastName, function( response ) {
        // console.log( response ); // server response
        response = response.trim();
        if(response == 1){
            alert("Everything is alright");
        } else{
            alert(response);
            return false;
        }
    });
}

并将您的表格更改为:

<form class="register" action="regist.php" method="post" onSubmit="checkAll();">

Now the key is that in the validation.php ,if everything works fine then you can echo value 1, and when something is not alright, you echo the error code ( or any code, and then with an switch clause you can dynamically add the error to your form).

The return false prevents the form from submitting...

于 2013-04-24T05:47:10.553 回答