codeigniter 2在1个视图中形成 - 只有1个表单正在工作

时间:2014-12-15 18:36:37

标签: php forms codeigniter

我在一个视图中有这2个表单,但我感到困惑,因为每次执行操作时只接受第一个表单。当我选择填写第二个表单时,它会将其路径重定向到第一个表单。下拉表单工作正常,但如果我尝试填写搜索表单,它会重定向到管理员中的下拉功能控制器(admin_randc_dropdresult()),而不是重定向到控制器的搜索功能(admin_randc_search())我一直试图解决这个问题,但我似乎无法找到问题所在。任何帮助将不胜感激

这是我包含两个视图的视图

<div class="table-responsive">
         <table border='1'>
            <tr>
              <td>
             <?php include 'randc_dropdown.php';?>
             </td>

              <td>
             <?php include 'randc_search.php'; ?>
              </td>
           </tr>
         </table>
       </div>

第一个视图

<?php echo form_open('admin/admin_randc_dropdresult'); ?>
<?php $options = array('0' => 'Choose Option',
                          '1'  => 'Garden Plaza',
                          '2'    => 'Cafe Treveno',
                        );
                ?>
    <table border='1'>
        <tr>
            <td>
                <div class="form-group">
                <?php echo form_label("Select Restaurant:",'class="form-control"'); ?>
                </div>
            </td>

            <td>
                <div class="form-group">
                <?php echo form_dropdown('restos', $options, '0', 'class="form-control"');?>
                </div>
            </td>
            <td>
                <div class="form-group">
                <?php echo form_submit('admin_randc_dropdresult','Go','class="btn btn-info btn-sm" type="dropdown" id="Go"');?>
                </div>
            </td>
        </tr>
    </table>

<?php form_close();?>

第二视图:

<?php echo form_open('admin/admin_randc_search'); ?>

        <table border='1'>
            <tr>
                <td>
                        <div class="form-group">
                            <?php echo form_input('resto_name','','placeholder="Restaurant Name"','class="form-control"'); ?>
                        </div>
                </td>
                <td>
                        <div class="form-group">
                        <?php echo form_submit('Submit','Search','class="btn btn-info btn-sm" type="Search" id="Search"');?>
                        </div>
                </td>
            </tr>
        </table>

<?php form_close();?>

这是我的控制器

public function admin_randc_dropdresult()
{
    if($this->session->userdata('logged_in'))
    {
            $session_data = $this->session->userdata('logged_in');
            $data2['username'] = $session_data['username'];

        $options = array(
              '0'  => 'Choose option',
              '1'  => 'Garden Plaza',
              '2'    => 'Cafe Treveno',
            );
        $key = $this->input->post('restos');
        $value = $options[$key];

        $data['rc'] = $this->randc_model->randc_dropdown($value);
        $this->load->view('rates_comments/randc_dropdownresult',array_merge( $data2,$data));
    }
}
public function admin_randc_search()
{
    if($this->session->userdata('logged_in'))
    {

            $session_data = $this->session->userdata('logged_in');
            $data2['username'] = $session_data['username'];

        $resto_name = $this->input->post('resto_name');

        $data['rc'] = $this->randc_model->search_randc_specific($resto_name);
        $this->load->view('rates_comments/randc_searchresult',array_merge( $data2,$data));

    }
}

2 个答案:

答案 0 :(得分:0)

您仍然可以保持视图分离并保留一个控制器:

 if($this->input->post('submit_btn_name') === 'submit_value'){

        $options = array(
          '0'  => 'Choose option',
          '1'  => 'Garden Plaza',
          '2'    => 'Cafe Treveno',
        );
     $key = $this->input->post('restos');
     $value = $options[$key];

     $data['rc'] = $this->randc_model->randc_dropdown($value);
     $this->load->view('rates_comments/randc_dropdownresult',array_merge( $data2,$data)
   }

 elseif($this->input->post('other_btn) ==='other_submit'){

      $session_data = $this->session->userdata('logged_in');
      $data2['username'] = $session_data['username'];

      $resto_name = $this->input->post('resto_name');

      $data['rc'] = $this->randc_model->search_randc_specific($resto_name);
      $this->load->view('rates_comments/randc_searchresult',array_merge( $data2,$data);
 }

答案 1 :(得分:0)

是不是因为你没有回复表格? 这可能会破坏表格的分离,因为第一种形式不会正确关闭

<?php form_close();?>

应该是这个吗?

<?php echo form_close();?>