Codeigniter validation help
        Posted  
        
            by Drew McGhie
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Drew McGhie
        
        
        
        Published on 2010-05-24T20:33:55Z
        Indexed on 
            2010/05/24
            22:01 UTC
        
        
        Read the original article
        Hit count: 333
        
I'm writing a system where users can generate/run queries on demand based on the values of 4 dropdown lists. The lists are dynamically generated based on a number of factors, but at this point, I'm having problems validating the input using codeigniter's built in validation classes. I think I have things out of order, and I've tried looking at the codeigniter site, but I think I'm tripping myself up.
in my view(/dashboard/dashboard_index.php), I have the following code block:
<?=form_open('dashboard/dashboard_add');?>
        <select ... name='selMetric'>
        <select ... name='selPeriod'>
        <select ... name='selSpan'>
        <select ... name='selTactic'>
        <input type="submit" name="submit_new_query" value="Add New Graph" class="minbutton" ></input>
<?=form_close();?>
Then in my controller, I have the following 2 methods:
function index() {
        $this->load->helper(array('form', 'url'));
        $this->load->library('validation');
        //population of $data
        $this->load->tile('dashboard/dashboard_index', $data);
    }
function dashboard_add()
    {
        $rules['selMetric'] = "callback_sel_check";
        $rules['selPeriod'] = "callback_sel_check";
        $rules['selSpan'] = "callback_sel_check";
        $rules['selTactic'] = "callback_sel_check";
        $this->validation->set_rules($rules);
        $fields['selMetric'] = "Metric";
        $fields['selPeriod'] = "Time Period";
        $fields['selSpan'] = "Time Span";
        $fields['selTactic'] = "Tactic";
        $this->validation->set_fields($fields);
        if ($this->validation->run() == false) {
            $this->index();
        } 
        else {
            //do stuff with validation information
        }
    }
Here's my issue. I can get the stuff to validate correctly, but for the number of errors I have, I get
Unable to access an error message corresponding to your field name.
as the error message for everything. I think my issue that I have the $rules and $fields stuff in the wrong place, but I've tried a few permutations and I just keep getting it wrong. I was hoping I could get some advice on the correct place to put things.
© Stack Overflow or respective owner