将表单数据和变量(ID)传递给控制器​​函数codeigniter

时间:2015-08-31 10:00:48

标签: php codeigniter

我想将变量(id)和表单数据传递给控制器​​函数。代码如下:

<form action = "index.php/my_controller/my_function" method = "POST">

   <input name = "comment" type = "text" size = "8">
   <input type = "submit" value = "save">
</form>

  <?php
     my_function($id){
                      // get the text
                      // get the id 
                      //save id and text
                     }  
  ?>

当我尝试

`action = "index.php/my_controller/my_function/<?php echo record['ID']?>"`

其中$ record ['id']给我id,URL显示id,但是我如何将它传递给控制器​​文件中的my_function($ id)。

1 个答案:

答案 0 :(得分:2)

尝试使用隐藏字段

<form action = "index.php/my_controller/my_function" method = "POST">
   <input name = "id" type = "hidden" value="<?php echo $id; ?>">
   <input name = "comment" type = "text" size = "8">
   <input type = "submit" value = "save">
</form>