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 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化