【问题标题】:two submit button inside one form in codeignitercodeigniter中一个表单内的两个提交按钮
【发布时间】:2016-08-01 13:12:07
【问题描述】:

嗨,我想在代码点火器中以一种形式有两个提交按钮。可能吗?我想做两个按钮,它们会做同样的事情,将数据添加到数据库中,按钮的唯一区别是它们将重定向到哪个页面。

这是我的代码,

<?php

  echo form_open('EmpFamilyInfo/add_childinfo/'.$this->uri->segment(3));


?>
// some textboxex,
    <div class="box-body">
      <div class = 'col-md-6 col-sm-offset-6'>
        <button class="btn btn-info fa fa-save" type="submit">&nbsp Save</button>
        <a href = '<?php echo base_url().'EmpFamilyInfo/other_childinfo/'.$this->uri->segment(3); ?>' class = 'btn btn-primary fa fa-save' >&nbsp Add Another</a>
        <a href = '<?php echo base_url().'EmpFamilyInfo/parentsinfo_father/'.$this->uri->segment(3); ?>' class = 'btn btn-danger fa fa-arrow-circle-right'>&nbsp Skip</a>


     <?php

      echo form_close();
    ?>
      </div>
    </div>

我已经制作了这个代码,第一个链接echo form_open('EmpFamilyInfo/add_childinfo/'.$this-&gt;uri-&gt;segment(3));我想要这样做是

public function other_childinfo(){

    $this->form_validation->set_rules('NAME',   'Name of Child' ,'trim|required|max_length[100]');

    if($this->form_validation->run($this) == FALSE){

        $this->child_info();
    }else{

        if($query = $this->EmpFamilyInfo_Model->insert_childinfo()){

            redirect('EmpFamilyInfo/child_info/'.$this->uri->segment(3));

        }else{

            $this->child_info();
        }
    }   
}

但错误是,它没有发布数据。我怎样才能让这个链接成为提交按钮,但它会转到不同的功能,或者我怎样才能让它拥有发布数据?

【问题讨论】:

  • 你的代码有two anchor tag而不是两个提交按钮!!
  • 是的。我知道。我希望其中一个用作提交按钮。
  • imo - 为提交按钮指定不同的名称,然后检查控制器中实际使用的名称并根据需要重定向?无需 javascript。

标签: php forms codeigniter


【解决方案1】:

这个问题已经在这个网站上得到了回答,所以这个回答不是我的,只是为你引用: 这使用了 javascript,因此请记住,禁用此功能的用户将无法使用此解决方案。

<script type="text/javascript">
    function submitForm(action)
    {
        document.getElementById('form1').action = action;
        document.getElementById('form1').submit();
    }
</script>

...

<input type="button" onclick="submitForm('page1.php')" value="submit 1" />
<input type="button" onclick="submitForm('page2.php')" value="submit 2" />

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-10-07
  • 2018-03-29
  • 1970-01-01
  • 1970-01-01
  • 2016-12-01
  • 1970-01-01
相关资源
最近更新 更多