给提交按钮一个值CodeIgniter


giving a submit button a value CodeIgniter

我想给提交按钮一个值。我看过这个视频,

https://www.youtube.com/watch?v=FUZ_GGSggLA

但我正在使用CodeIgniter,所以它给了我一个错误。

我已经做到了:

<?php
  echo form_open('Mycontroller/thisfunction/'.$this->uri->segment(3));

?>
        <button class="btn btn-info fa fa-save" type="submit" name ="1">&nbsp Save</button>
        <button class="btn btn-primary fa fa-save" type="submit" name ="2">&nbsp Save1</button>
    <?php
      echo form_close();
    ?>

和我的控制器:

public function thisfunction(){
    if($_POST['1']){
        echo "1";
    }else if($_POST['2']){
        echo "2";
    }
}

但是我得到了错误Message: Undefined offset: 1Message: Undefined offset: 2。。

我需要这个代码,因为我会这样使用它:

    if(THIS BUTTON IS USED){
        redirect it to this page
    }else if(THIS BUTTON IS USED){
        redirect it to other page
    }

在控制器中

public function thisfunction(){
  if( isset($_POST['1']) ){
      echo "1";
  } else {  
      //else if not needed, if not '1' it has to be '2'
      echo "2";
  }
}

首先,您需要检查它是否已设置例如

$formdata = $this->input->post();
           if(isset($formdata['1'])){
                      echo "1";
                     }
                  else{
                         echo "2"
                       }