CodeIgniter Forums
Manually adding an error to form validation - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Manually adding an error to form validation (/showthread.php?tid=25972)



Manually adding an error to form validation - El Forum - 01-02-2010

[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!


Manually adding an error to form validation - El Forum - 01-02-2010

[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.


Manually adding an error to form validation - El Forum - 01-03-2010

[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?


Manually adding an error to form validation - El Forum - 01-03-2010

[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));