3

我正在处理基于此的编辑预订和调整付款。如果预订延长,那么我需要向客户收取这部分费用,同样,如果它被缩短,我需要退款。

我尝试了这样的事情(实际上没有发布任何内容,只是一个确认框),但即使按下取消它仍然提交了表单。

<?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>

有可能做这样的事情吗?正如我之前提到的,当我按下取消时,仍然提交了表单。

4

1 回答 1

1

查看此现场演示: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;
}
于 2013-09-04T19:09:01.310 回答