Welcome Guest, Not a member yet? Register   Sign In
Is there a way to force form validation errors?
#1

[eluser]Unknown[/eluser]
I am running through my form_validation->set_rules() which works fine, but is there a way to do a force failure say for example:

$this->form_validation->set_rules();
$this->form_validation->set_rules();
$this->form_validation->set_rules();
if($x==FALSE){$this->form_validation->force_error('message');}

$this->form_validation->run()


Is something like that possible?
#2

[eluser]Clooner[/eluser]
this can be implemented using callbacks
#3

[eluser]Unknown[/eluser]
[quote author="Jeroen Schaftenaar" date="1357054654"]this can be implemented using callbacks[/quote]

Thanks, can you give me an example or a link to read up on?

$x is a variable set within the function processing the form, based on several inputs of the form.. not directly from the form itself.
#4

[eluser]InsiteFX[/eluser]
See this forum topic
#5

[eluser]Clooner[/eluser]
It's explained in the user guide. http://ellislab.com/codeigniter/user-gui...#callbacks
#6

[eluser]leighmarble[/eluser]
[quote author="Clooner" date="1357075588"]It's explained in the user guide. http://ellislab.com/codeigniter/user-gui...#callbacks[/quote]

This worked great for me, just by following the user guide (no tutorials needed).

Just one addendum to the user guide: make sure that the callback function itself is declared as public. I initially made mine private, since I figured it would only be called from within the same controller. However, since it's the Form Validation class that actually calls it, it needs to be accessible from outside the controller.




Theme © iAndrew 2016 - Forum software by © MyBB