Welcome Guest, Not a member yet? Register   Sign In
Manually adding an error to form validation
#1

[eluser]koryrok[/eluser]
Hi All,

I have a need to manually add an error to the error array that codeigniter generates. Basically I want a custom error to show up when I use:
Code:
<?php echo validation_errors(); ?>

Thanks!
#2

[eluser]Colin Williams[/eluser]
Errors correspond to fields, so if you want to use the validation class as your core error reporting class (bad idea IMO), then you need to setup "dummy" fields just to hold the errors. A better idea is to just pass custom errors from the controller to the view, and then echo them there. The output of validation_errors() can be a part of this, of course.
#3

[eluser]koryrok[/eluser]
Hi Collin,

That's what I'm asking, how do I pass custom errors from my controller to my view and show them using the validation_errors() call?
#4

[eluser]Colin Williams[/eluser]
The second parameter of $this->load->view() accepts an array where you could add variables directly to the view. Or, you can add variables globally to views with $this->load->vars(). Check the docs for more info.

Code:
$errors = validation_errors();
$errors .= 'Some other error';
$this->load->vars(array('form_errors' => $errors));




Theme © iAndrew 2016 - Forum software by © MyBB