为CakePHP创建自定义确认弹出窗口


Creating custom confirm popup for CakePHP

我正在处理编辑预订并在此基础上调整付款。如果预订时间延长,我需要向客户收取费用,同样,如果预订时间缩短,我需要退款。

我试过这样的东西(实际上没有张贴任何东西,只是一个确认框),但即使按下取消键,它还是提交了表格。

<?php echo $this->Form->create('edit',array('onsubmit'=>'return check_dates()')); ?>
//rest of form here
<script>
function check_dates(){
   //make POST request to check previous reservation duration
   if(data.duration == 'longer'){
       confirm('The guest will be charged $X. Click OK to continue');
   }
   if(data.duration == 'shorter'){
       confirm('The guest will be refunded $X. Click OK to continue');
   }
   if(data.duration == 'no_change'){
       confirm('Click OK to continue')
   }
}
</script>

有可能做这样的事吗?正如我之前提到的,当我按下取消键时,无论如何都提交了表格。

查看此实时演示:http://jsbin.com/iZididi/2

在check_dates()中,您必须设置return。如果你想让表格提交任何答案,只要确认你就可以将最后一行替换为

function check_dates(){
     data = new Object();
  data.duration = 'shorter';
  if(data.duration == 'longer'){
       a = confirm('The guest will be charged $X. Click OK to continue');
   }
   if(data.duration == 'shorter'){
       a = confirm('The guest will be refunded $X. Click OK to continue');
   }
   if(data.duration == 'no_change'){
      a = confirm('Click OK to continue')
   }
  //return a;
  return true;
}