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 python变量和列表之间的相互影响
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)