根据选择选项加载不同的视图

时间:2015-02-25 13:27:33

标签: codeigniter select

查看:                                                    付款方式:

                        <select name="payment" id="payment"> 
                        <option value="">  --- Select ---</option>
                        <option value="cash">Cash on Delivery</option>
                        <option value="online">Digital/Online Payment</option>


                        </select>
                      </label><?php echo form_error('payment'); ?></td>
                  </tr>

控制器:

public function save_order()

{
    $this->load->library('form_validation');

    $this->form_validation->set_rules('name', 'name', 'required|trim|max_length[50]');          
    $this->form_validation->set_rules('phone', 'phone', 'required|trim|is_numeric|min_length[9]');          
    $this->form_validation->set_rules('time', 'time', 'required');          
    $this->form_validation->set_rules('location', 'location', 'required');          
    $this->form_validation->set_rules('address', 'address', 'required|trim|xss_clean|max_length[300]');
    $this->form_validation->set_rules('payment', 'payment', 'required');

    $this->form_validation->set_error_delimiters('<br /><span class="error">', '</span>');

    if ($this->form_validation->run() == TRUE && ($payment = "cash"))

{ $这 - &GT;负载&gt;查看( 'billing_view');         其他         {             $这 - &GT;负载&gt;查看( 'billing_view2'); }

我正在尝试根据表单中的选择选项加载不同的页面,但它似乎不起作用。 建议请?

1 个答案:

答案 0 :(得分:0)

public function save()
    { 
        //If form validation returns false,
        //call the index method(form) and return from the method
        //so nothing else gets executed
        if(!$this->form_validation->run()){
            return $this->index();
        }

        $payment = $this->input->post("payment");

        //If payment type is == cash
        //load the view called cash and return from method
        //so nothing else gets executed
        if($payment == "cash"){
            return $this->load->view('cash');
        }

        //default method behaviour if none of the above
        //are true.
        return $this->load->view("digital");
    }