Php 如何在jQuery模式确认对话框之后提交表单?

Php 如何在jQuery模式确认对话框之后提交表单?,php,javascript,jquery,jquery-ui-dialog,Php,Javascript,Jquery,Jquery Ui Dialog,此脚本在提交表单之前打开jQuery对话框/modal以请求验证,但是当用户单击modal窗口中的“Submit”按钮时,什么也没有发生。Firebug发现问题出在包含“document.leaveReq.submit();”的行上 我对jQuery和javascript非常陌生,已经为这一点挣扎了几天。非常感谢您的帮助 $(document).ready(function() { // jQuery UI Dialog $('#dialog').dialog({

此脚本在提交表单之前打开jQuery对话框/modal以请求验证,但是当用户单击modal窗口中的“Submit”按钮时,什么也没有发生。Firebug发现问题出在包含“document.leaveReq.submit();”的行上 我对jQuery和javascript非常陌生,已经为这一点挣扎了几天。非常感谢您的帮助

$(document).ready(function() {

    // jQuery UI Dialog    
    $('#dialog').dialog({
        autoOpen: false,
        width: 400,
        modal: true,
        resizable: false,
        buttons: {
            "Submit": function() {
                document.leaveReq.submit();
                return true;
            },
            "Cancel": function() {
                $(this).dialog("close");
                return false;
            }
        }
    });
    $('#formerror').dialog({
        autoOpen: false,
        modal: true,
        resizable: false,
        buttons: {
            "Back": function() {
                $(this).dialog("close");
                return false;
            }
        }
    });

    $('#verify').click(function(e){
        e.preventDefault();
        if( !$("input#from").val() || !$("input#to").val()){
            $("span#error-message").html('Provide a starting and ending date.');
            $('#formerror').dialog('open');
        } else if( $("input#amount").val() == 0 ){
            $('#formerror').dialog('open');
            $("span#error-message").html('Provide the number of units that you will use.');
        } else if( !$("textarea#description").val() ){
            $("span#error-message").html('Provide the reason for this leave request.');
            $('#formerror').dialog('open');
        } else {
                $("span#leavedescriptionidentification").html(document.getElementById('leave_description_identification').options[document.getElementById('leave_description_identification').selectedIndex].value);
            $("span#startingdate").html($("input#from").val());
            $("span#endingdate").html($("input#to").val());
            $("span#amount").html($("input#amount").val());
            $("span#description").html($("textarea#description").val());
            $('#dialog').dialog('open');
        }
        return false;
    });
});
</script>
<form action="/leave/lvereq" method="post" id="leaveReq" name="leaveReq" accept-charset="utf-8">
<div id="add">
    <table>
        <tr>
            <td class="label"><label for="leave_description_identification">Leave Type:</label></td>
            <td class="ret_text"><select id="leave_description_identification" name="leave_description_identification" class="scrolledlist">
                    <option ...>...</option>
                    </select>
            </td>
        </tr>
        <tr>
            <td class="label"><label for="starting_date">Start Date:</label></td>

            <td class="ret_text"><input type="text" id="from" name="starting_date" /></td>
        </tr>
        <tr>
            <td class="label"><label for="ending_date">Ending Date:</label></td>
            <td class="ret_text"><input type="text" id="to" name="ending_date" /></td>
        </tr>
        <tr>
            <td class="label"><label for="amount">Number of Units:</label></td>

            <td class="ret_text"><input type="text" id="amount" name="amount" alt="signed_decimal_value_3" class="signed_decimal_value_3" onFocus="getCalc();" /></td>
        </tr>
        <tr>
            <td class="label"><label for="description">Reason For Leave:</label></td>
            <td class="ret_text"><textarea id="description" name="description" value="200" cols="60" rows="7" class="scrolledtext" wrap="soft"></textarea></td>

        </tr>
    </table>

</div>

<div class="formButtons">
    <span class="formButton">
        <a id="verify" name="verify" href="#" class="ui-state-default ui-corner-all" style="padding:3px 8px;">Submit</a>
        <input type="submit" id="submit" name="submit" value="Submit" />
    </span>
</div>

</form>

<div id="dialog" title="Confirmation">
    <p>
        <span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 0 0;"></span> Please verify the the information you entered is correct:
    </p>
    <p>
        <span class="label">Type:</span> <span id="leavedescriptionidentification"></span><br />
        <span class="label">Dates:</span> <span id="startingdate"></span> - <span id="endingdate"></span><br />
        <span class="label">Unit Amount:</span> <span id="amount"></span><br />

        <span class="label">Reason:</span> <span id="description"></span>
    </p>
    <p>If this is correct, click Submit.</p>
    <p>To edit, click Cancel.<p>
</div>

<div id="formerror" title="Error">
    <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 0 0;"></span> Please correct the following error:</p>

    <p><span id="error-message"></span></p>
</div
$(文档).ready(函数(){
//jQueryUI对话框
$('#dialog')。dialog({
自动打开:错误,
宽度:400,
莫代尔:是的,
可调整大小:false,
按钮:{
“提交”:函数(){
document.leaveReq.submit();
返回true;
},
“取消”:函数(){
$(此).dialog(“关闭”);
返回false;
}
}
});
$('#formerror')。对话框({
自动打开:错误,
莫代尔:是的,
可调整大小:false,
按钮:{
“Back”:函数(){
$(此).dialog(“关闭”);
返回false;
}
}
});
$(“#验证”)。单击(函数(e){
e、 预防默认值();
if(!$(“输入#从”).val()| |!$(“输入#到”).val()){
$(“span#错误消息”).html('提供开始和结束日期');
$('#formerror')。对话框('open');
}else if($(“输入#金额”).val()=0){
$('#formerror')。对话框('open');
$(“span#错误消息”).html('提供您将使用的单位数');
}else if(!$(“textarea#description”).val(){
$(“span#错误消息”).html('提供此请假请求的原因');
$('#formerror')。对话框('open');
}否则{
$(“span#leavedescriptionidentification”).html(document.getElementById('leave#description#identification')。选项[document.getElementById('leave#description#identification')。selectedIndex]。值);
$($(span#startingdate”).html($($(input#from”).val());
$($span#endingdate”).html($($input#to”).val();
$($span#amount”).html($($input#amount”).val());
$($span#description”).html($($textarea#description”).val();
$('dialog')。dialog('open');
}
返回false;
});
});
休假类型:
...
开始日期:
截止日期:
单位数量:
请假理由:

请验证您输入的信息是否正确:

类型:
日期:-
单位金额:
原因:

如果正确,请单击提交

要编辑,请单击“取消”。 请更正以下错误:


在对话框的提交功能中,尝试:

"Submit": function() {
    $('form#leaveReq').submit();
    return true;
},

您确定您的验证没有阻止表单提交吗?上面的调用应该可以工作。Well无法确定发生了什么,所以我离开了验证检查并删除了确认模式。这似乎足够了,而且效果很好。