hi我想在代码点火器中的一个表单中有两个提交按钮。有可能吗?我想制作两个按钮,它们将做同样的事情,将数据添加到数据库中,按钮的唯一区别是它们将重定向到哪个页面上。
这是我的代码,
<?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">  Save</button>
<a href = '<?php echo base_url().'EmpFamilyInfo/other_childinfo/'.$this->uri->segment(3); ?>' class = 'btn btn-primary fa fa-save' >  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'>  Skip</a>
<?php
echo form_close();
?>
</div>
</div>
我已经制作了第一个链接echo form_open('EmpFamilyInfo/add_childinfo/'.$this->uri->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();
}
}
}
但错误在于,它没有发布数据。我如何使这个链接成为一个提交按钮,但它将转到不同的功能,或者我如何使它具有发布数据?
这个问题已经在这个网站上得到了回答,所以这个回答不是我的,只是为你引用:这使用了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" />