2016-01-23 70 views
0

我正在寫一個管理面板的頁面,我正在製作該列表成員結果。我想在此頁面上搜索表單以搜索特定成員。由於我在此頁面上有其他表單,因此此搜索表單的操作必須採用與我的控制器不同的方法。問題是沒有任何後期值傳輸到搜索方法。我究竟做錯了什麼?如何在CodeIgniter中的另一個頁面上使用一個頁面上的表單?

class Users extends MY_Controller { 

    function __construct(){ 
     parent::__construct(); 
    } 

    function index(){ 

     if(!$this->form_validation->run()){ 

     $this->load->view('users/index'); 

     } 

    } 

    function search(){ 

     $criteria = $this->input->post('search_criteria'); 

    } 

} 

這有點像什麼我的看法是:

<?php echo form_open('users/search'); ?> 
<input type="text" name="search_criteria"> 

回答

0

你沒有form validation rules和表單驗證是在錯誤的函數

class Users extends MY_Controller { 

function __construct(){ 
    parent::__construct(); 
    $this->load->library('form_validation'); 
    $this->load->helper('form'); 
    $this->load->helper('url'); 
} 

function index(){ 
    // There is no need to use index on your view files. 
    $this->load->view('users'); 
} 

function search(){ 

    $criteria = $this->input->post('search_criteria'); 

    $this->form_vadliation->set_rules('search_criteria', 'Search', 'required'); 

    if($this->form_validation->run() == FALSE) { 

     // There is no need to use index on your view files. 
     $this->load->view('users'); 

    } else { 

     // Success Stuff 

    } 

} 

} 

View應用程序>的意見> users.php

<?php echo validation_errors('<div class="error">', '</div>'); ?> 

<?php echo form_open('users/search'); ?> 

<input type="text" name="search_criteria" value="" class="" placeholder="" /> 

<input type="submit" value="Save" /> 

<?php echo form_close();?>