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 socket通信实现多人聊天室疑惑
  • ¥15 DEV-C++编译缺失
  • ¥33 找熟练码农写段Pyhthon程序
  • ¥100 怎么让数据库字段自动更新
  • ¥15 antv g6 力导向图布局
  • ¥15 quartz框架,No record found for selection of Trigger with key
  • ¥15 锅炉建模+优化算法,遗传算法优化锅炉燃烧模型,ls-svm会搞,后面的智能算法不会
  • ¥20 MATLAB多目标优化问题求解
  • ¥15 windows2003服务器按你VPN教程设置后,本地win10如何连接?
  • ¥15 求一阶微分方程的幂级数