我有一个注册表单,目前在一个用 jQuery 编码的弹出模式窗口中。我在底部有一个 PHP 提交按钮,并且我添加了 jQuery 代码来阻止按钮提交。这是因为它会在我提交页面时阻止我的模式窗口关闭。我现在的问题是提交表格是不可能的。有没有办法在所有这些拥挤的弹出窗口和 jQuery 上提交我的表单?说是否可以使用 AJAX 或 jQuery 提交表单并允许我的 PHP 处理它。
因为我是用 PHP 编写的,所以有相当多的服务器端验证正在进行,所以这样做的目的是让我的查看者在模式窗口关闭之前修复他们的验证错误。
这是我的 jQuery,我不再打扰它,因为它可以满足我的需要。
$(document).ready(function() {
    $('a.modal-window').click(function() {          
                //Getting the variable's value from a link 
        var loginBox = $(this).attr('href');   
        $(loginBox).fadeIn(300);        
        var popMargTop = ($(loginBox).height() + 24) / 2; 
        var popMargLeft = ($(loginBox).width() + 24) / 2;           
        $(loginBox).css({ 
            'margin-top' : -popMargTop,
            'margin-left' : -popMargLeft
        });         
        // Add the mask to body
        $('body').append('<div id="mask"></div>');
        $('#mask').fadeIn(300);         
        return false;
    });     
    // When clicking on the button close or the mask layer the popup closed
    $('a.close, #mask').live('click', function() { 
      $('#mask , .login-popup').fadeOut(300 , function() {
        $('#mask').remove();  
    }); 
    return false;
    });
});
这是我用来阻止表单提交的代码:
$(function () {
    $(':submit').click(function (event) {
        event.preventDefault();
        // submit the form dynamically
    });
});
下面是我的表格,尽管它在那里供观看,但可能并不重要。
<form method="post" id="loginform"  action="<?php echo $_SERVER['PHP_SELF']?>">
                <table style="color: white;">
                    <tr><th style="float:left;">Register a new account with us.</th></tr>
                    <tr><td>Username</td><td><input type="text" name="txtUser"/></td></tr>
                    <tr><td>Password</td><td><input type="text" name="txtPass"/></td></tr>
                    <tr><td>Email</td><td><input type="text" name="txtEmail"/></td></tr>
                    <tr><td>Confirm Email</td><td><input type="text" name="txtEmail2"/></td></tr>
                    <tr><td>First Name</td><td><input type="text" name="txtFname"/></td></tr>
                    <tr><td>Last Name</td><td><input type="text" name="txtLname"/></td></tr>
                    <tr><td>Address</td><td><input type="text" name="txtAddress"/></td></tr>
                    <tr><td>City</td><td><input type="text" name="txtCity"/></td></tr>
                    <tr><td>Postal Code</td><td><input type="text" name="txtPostal"/></td></tr>
                    <tr><td>Birth Year</td><td><input type="text" name="txtBirth"/></td></tr>
                    <tr><td>Gender</td><td><input type="radio" id="radio-1-1" name="radicalSex" class="regular-radio" value="m" selected="true" /><label for="radio-1-1"></label> Male</td></tr>
                    <tr><td></td><td><input type="radio" id="radio-1-2" name="radicalSex" class="regular-radio" value="f"/><label for="radio-1-2"></label> Female</td></tr>
                    <tr><td colspan='2' style="color: #FF6600;float:left;font-size:70%;"><?php echo $Error;?></td></tr>
                    <tr><td colspan="2"><input type="submit" name="btnRegister" ID="btnBlueTemp" value="Submit Registration" /></td></tr>
                    <tr><td colspan='2' style="float:left; font-size:70%;">Address information is optional</td></tr>
                </table>      
          </form>