dragon188199 2012-09-13 13:36
浏览 26
已采纳

CodeIgniter - 在视图中形成2个表单

I have a view which has 2 forms:

<table>
<th>Write a comment.</th>
<tr>
    <td>
        <?php echo form_open($this->uri->uri_string(),$form1); 
              echo form_textarea($comment);
              echo form_submit('submit','submit');
              echo form_close();
        ?>
    </td>
</tr> 


</table>

<table>
    <tr>

        <td>
            <?php echo form_open($this->uri->uri_string()); 
                  echo form_dropdown('portion', $portion_options); 
                  echo form_submit('book','book');
                  echo form_close();
            ?>
        </td>
    </tr>
</table>

In the controller I check which button was clicked and then I perform some action by adding the corresponding form's values to the database.

if(isset($_POST['book']))
{
    //sending the data to the database
    echo "Book button clicked";
}

if(isset($_POST['submit']))
{
   //sending the data to the database
   echo "Submit button clicked";
}

However when the 'book' button is clicked no action is performed. It is like the button was never clicked. Whereas when I click the 'submit' button, every action is done properly.

In the past I have used the same technique on plain php (i mean no framework, just php), and has worked fine for me. Does codeigniter need any further configuration? Am I doing something wrong?

  • 写回答

3条回答 默认 最新

  • dqpfkzu360216 2012-09-13 14:13
    关注

    Why not add a hidden field to both forms called form_idwith values 1 and 2 respectively? Easy to catch in your controller upon post; e.g.:

    if($this->input->post()){
      switch($this->input->post('form_id')){
      case 1:
        // do stuff
      break;
      case 2:
        // do stuff
      break;
      }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题