jquery.ui对话框确认删除没有返回值到PHP

时间:2011-04-14 08:09:55

标签: jquery user-interface dialog confirm

在谷歌搜索和研究4-5小时后,触发表单提交不会按预期将字段值返回给php ...感谢任何帮助

<?php   
if (isset($_POST['xxxx'])){
    echo "POST DELETE  <br />";
}else{
?>
  <div id="dialog_confirm" title="Confirm Delete">Are you sure ?</div>
  <form id='inputform' name='tablename' method='post' action='#' />
    <input type='text' name='xxxx' value='22' />
    <input type='submit' class='delete' name='delete' value='Delete' />
  </form>

  <script type='text/javascript'>
    jQuery(document).ready(function(){
       $('#inputform').submit( function(){
       $("#dialog_confirm").dialog('open'); 
          return false;
       });
       $( "#dialog_confirm" ).dialog({
          autoOpen:     false,
          resizable: false,
          height:140,
          modal: true,
          buttons: {
            "Delete all items": function() { 
              $( this ).dialog( "close" );
              window.inputform.submit();
            },
            Cancel:     function() { $( this ).dialog( "close" );}
          }
       });              
    });
  </script>

1 个答案:

答案 0 :(得分:1)

这是因为你的回报是假的;这里:

$('#inputform').submit( function(){
       $("#dialog_confirm").dialog('open'); 
          return false;
});

因此,每当您尝试从表单提交数据时,它永远不会。您想在提交按钮上使用click()。

你可能想试试这个:

$('.delete').click( function(){ //Submit button clicked (or return key pressed)
       $("#dialog_confirm").dialog('open'); 
       return false; //Don't submit the form straight away
});

$( "#dialog_confirm" ).dialog({
            resizable: false,
            autoOpen: false,
            height:140,
            modal: true,
            buttons: {
                "Delete all items": function() {
                    $('#inputForm').submit(); //Now submit the form
                    $( this ).dialog( "close" );
                },
                Cancel: function() {
                    $( this ).dialog( "close" );
                }
            }
 });