dpn4073 2016-09-16 05:54
浏览 36
已采纳

如何在php codeigniter中获取输入字段的隐藏ID

I am doing a project with code igniter in which i have a form that contains a list of students.My form is as follows:

<form action = 'my_controller/my_method' method = "post">
 <table>
   <thead>
     <tr>
       <th>Roll</th>
       <th>Name</th>
       <th></th>
     </tr>
    </thead>
     <tbody>
       <?php foreach ($students as $row) { ?>
       <tr>
          <td><?php echo $row->roll; ?></td>
          <td><?php echo $row->name; ?></td>
          <input type = "hidden" name = "class_id" value = "<?php echo $row->class_id; ?>" />
          <input type = "hidden" name = "student_id" value = "<?php echo $row->student_id; ?>" />
          <td><input type="submit" value="some value" class= "btn btn-info"></td>
       </tr>
      </tbody>
   </table>
</form>

In my controller i need to get the hidden inputs. ie; class_id and student_id. class_id is same for all 's in the table. But student_id is varying. How can i get the student_ids in each form submit. Iam getting this class_id in my controller by $class_id = $this->input->post('class_id'); Thanks in advance. My controller method is

 function my_method(){ 
   $class_id = $this->input->post('class_id');
   $student_id = $this->input->post('student_id'); 
   echo $student_id; 
 }
  • 写回答

2条回答 默认 最新

  • douhaoqiao9304 2016-09-16 06:46
    关注

    You can use button or anchor tag instead of submit, and can pass the student_id and class_id as parameters to the method and can use them further in your function or method. For example, I am using anchor tag as submit:

    view:

    <table>
          <thead>
            <tr>
                <th>Roll</th>
                <th>Name</th>
                <th></th>
            </tr>
         </thead>
         <tbody>
           <?php foreach ($students as $row) { ?>
           <tr>
              <td><?php echo $row->roll; ?></td>
              <td><?php echo $row->name; ?></td>
              <input type = "hidden" name = "class_id" value = "<?php echo $row->class_id; ?>" />
              <input type = "hidden" name = "student_id" value = "<?php echo $row->student_id; ?>" />
              <td>
                <a href="<?php echo base_url();  . 'conroller/method/' . $row->class_id . '/' . $row->student_id ?>" class="btn btn-info" > submit</a>
              </td>
           </tr>
         </tbody>
    

    controlller::

    class conroller extends CI_controllers{
         function method($classId, $studentId){
                // use classId and studentId here
               echo 'class id = ' . $classId;
               echo 'student id = ' . $studentId;
         }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)