0

I wanted to give my submit button a value. I have watched this video,

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

but I am using CodeIgniter so it gave me an error.

I have already done this:

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

and my controller:

public function thisfunction(){

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

but I got the error Message: Undefined offset: 1 and Message: Undefined offset: 2..

I need this code because I will be using it like this:

    if(THIS BUTTON IS USED){
        redirect it to this page
    }else if(THIS BUTTON IS USED){
        redirect it to other page
    }
Sparky
  • 98,165
  • 25
  • 199
  • 285
kev_m
  • 325
  • 7
  • 30
  • Apparently `$_POST['1']` is looking at item #1 in the post array instead of the item named `"1"`. So what happens when you use letters for the `name` instead of a number? – Sparky Apr 11 '16 at 18:34

2 Answers2

0

In the controller

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

First of all you need to check whether it is set or not eg.

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

                  else{
                         echo "2"
                       }