[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:
<?=validation_errors()?>
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