dongzhuo7291 2018-06-20 06:42 采纳率: 100%
浏览 62
已采纳

如何避免在codeigniter中双击时间插入两次

I am search the other result of related question and that i implement in my code but that not working ,i have 2 button in a form

my form

<form id="InVoice" action="<?php echo  base_url('Staff/add_invoice_spare');?>" method="post" class="form-horizontal">


    /*-- content herer--*/


<button style="float:right;" type="submit" name="ready" value="Ready For Bill" class="btn btn-danger" style="border-radius:60px;">Add to Ready for Bill</button>

<button style="float:right;margin-left:15px;" type="submit" name="print" class="btn btn-danger" style="border-radius:60px;">Print</button>

<?php echo form_close(); ?>

and used script is

<script type="text/javascript">
 $(document).ready(function() {
    $("form#InVoice").submit(function() {
        alert();
        $('button[type=submit]').prop('disabled',true);
        return true;
    });
});
</script>

this my controller for inserting

public function add_invoice_spare()
  {
   $bill=$this->input->post('ready');
    if($bill)
    {
    $reg=$this->input->post('rno');
        $data=array(
              /*-----------datas here-----*/
                   );
    $ans=$this->Bill_model->check_registration($reg);
    $form_data=  $this->input->post();
    $result=$this->Bill_model->invoice_dtls_ready($form_data,$data);
        if($result){
                    redirect('Staff/list_invoice/'.$result);
                   }
    }else{
            $reg=$this->input->post('rno');
            $data=array(
              /*-----------datas here-----*/
                        );
            }
                $form_data=  $this->input->post();
                $result=$this->Bill_model->invoice_dtls($form_data,$data);
            if($result)
            {
            ?>
<script type="text/javascript" language="Javascript">
        window.open('invoice_pdf/<?PHP echo $result ?>', '_blank');
        window.location.href = "invoice_labour";
</script>
    <?php   }
        }
}

but in double click or single click the Add to Ready for Bill button the print button is work why that redirect?

any way to solve this issue and only one time submitte the data ? thanks in advance!!!

  • 写回答

1条回答 默认 最新

  • dousongqiang2585 2018-06-20 06:52
    关注

    Both the buttons that you are clicking on are of the type submit or they are submit buttons. So the only way to differentiate this will be at the backend.

    For eg, according to the above example when you submit the $_POST array will have the submit button value. It is based on this value that you have to build your code logics.

    If you click on Print then $_POST['submit'] will be the value will be print and when you click on "Add to Ready for Bill" the $_POST['submit'] value will be ready.

    If you want to control it in the Frontend i.e., jQuery end you can by using the preventDefault (the example of which is given by @pradeep) but I suggest you modify the Backend as well to differentiate between these 2 submit buttons.

    Hope this helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看