CodeIgniter Forums
using validation_errors() inside controller? - 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: using validation_errors() inside controller? (/showthread.php?tid=36125)



using validation_errors() inside controller? - El Forum - 11-22-2010

[eluser]fivestringsurf[/eluser]
Hey folks,
How do i echo validation errors from a controller?

I'm using jquery to perform an ajaxian type call to the controller. all my values pass to and from with no problems.
where i am running into trouble is with echoing out the validation errors using validation_errors()

using echo validation_errors(); seems to work in a view but not a controller?
all i need to do is echo out my validation errors from the controller and i will have myself a nifty ajax form validation service using jquery and codeigniter.

any suggestions?


using validation_errors() inside controller? - El Forum - 11-22-2010

[eluser]crikey[/eluser]
Could you just make a view that outputs the errors using validation_errors(), load the view into a variable in your controller, and echo the variable?

A bit of a roundabout way, but at least it keeps your output separate from your controller logic.


using validation_errors() inside controller? - El Forum - 11-30-2010

[eluser]fivestringsurf[/eluser]
Thanks for your response...sorry for the delay; Thanksgiving really swamped me.
Anyway, I got to the bottom of the problem.

I was calling exit(); immediately follwing the validation_errors() function and for some reason that was causing them not to print;
Strange; why would that be?
I ordered the script to stop after echoing the function.

Can anyone shed some light upon this?


using validation_errors() inside controller? - El Forum - 11-30-2010

[eluser]keithics[/eluser]
how about this..

if ($this->form_validation->run() == false)
{
echo validation_errors();


} else
{

}
exit;