Welcome Guest, Not a member yet? Register   Sign In
Displaying errors
#1

[eluser]ElliotReevey[/eluser]
I have been working on my first CodeIgniter project and have been overcoming several issues as I have progressed however I have hit another which I have been unable to find a decent solution to.

I have some code, as shown below:
Code:
$this->form_validation->set_error_delimiters('<li>', '</li>');
        $this->form_validation->set_rules('campaign_name', 'campaign name', 'trim|required|min_length[5]|xss_clean');
        $this->form_validation->set_rules('budget_amount', 'daily budget', 'trim|numeric|required');

        if ($this->form_validation->run() == true) {
            $slug = url_title($this->input->post('campaign_name'), 'underscore', TRUE);
            $check = $this->db->query('SELECT COUNT(*) as total FROM campaigns WHERE userid = "'.$sessionid.'" AND slug = "'.$slug.'"');
            $row = $check->row();
            if($row->total == 0) {
                $data = array('userid' => $sessionid, 'active' => '1', 'slug' => $slug, 'name' => $this->input->post('campaign_name'),'budget' => $this->input->post('budget_amount'));
                $this->db->insert('campaigns', $data);
                redirect('campaign/'.$slug);
            } else {
                //NEED TO PASS AN ERROR THROUGH HERE
            }
        }

The above code works fine and you will see my comment about where I would like to create a error message to pass back to the view if the condition is not met. I could easily pass this back to the view and display it on the screen however I already have
Code:
&lt;?=validation_errors()?&gt;
in my view therefore was trying to avoid adding another such function which essentially serves the same purpose.

Therefore my question is, is there anyway to add to the validation_errors() function and pass through my error message even though its not strictly a validation error from the form or will I have to create another function to deal with errors outside of the form validation?

Cheers
#2

[eluser]SPeed_FANat1c[/eluser]
I think you have to create another function, because validation_errors() will only show when $this->form_validation->run() is FALSE, but in your code it is TRUE, so it will not show anything.

If you could check for errors before checking

Code:
if ($this->form_validation->run() == true)

then you could make your own validation rule (read about callback functions http://ellislab.com/codeigniter/user-gui...#callbacks).




Theme © iAndrew 2016 - Forum software by © MyBB