给提交按钮一个值CodeIgniter

时间:2016-04-11 13:30:47

标签: php codeigniter submit codeigniter-3

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

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
    }

2 个答案:

答案 0 :(得分:0)

在控制器中

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

答案 1 :(得分:0)

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

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

                  else{
                         echo "2"
                       }