1

hi i want to have two submit button in one form in code igniter. is it possible? i want to make two buttons which will do the same thing, add data into the database, the only difference of the buttons is on which page they will redirect.

here is my codes,

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

i have made this code which the first link echo form_open('EmpFamilyInfo/add_childinfo/'.$this->uri->segment(3)); what i wanted this to do is

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();
        }
    }   
}

but the error is,that it does not have post data. how can i make this link a submit button but it will go to different function or how can i make it have the post data?

kev_m
  • 325
  • 7
  • 30

1 Answers1

0

this question ahs been answered already on this site, so this response is not mine, just quoting for you: This uses javascript so keep in mind users who have this disabled will not be able to use this solution.

<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" />
Rafael Lambelin
  • 286
  • 2
  • 10