I’m working on authorization system for Kohana. I’m doing it just for education…
This is how looks my controller that checks submitted fields:
$validation =
Validation::factory( $_POST )
->rule( 'username', 'not_empty' )
->rule( 'username', 'max_length', array( ':value', 32 ) )
->rule( 'username', 'alpha_dash', array( ':value', true ) )
->rule( 'password', 'not_empty' )
->rule( 'password', 'min_length', array( ':value', 6 ) )
->rule( 'password', 'max_length', array( ':value', 255 ) )
->rule( 'passwordRepeatedly', 'not_empty' )
->rule( 'passwordRepeatedly', 'matches', array( ':validation', 'passwordRepeatedly', 'password' ) )
->rule( 'email', 'not_empty' )
->rule( 'email', 'email' );
I’m looking for the way to display different error message for each added rule. My goal is then pass it (one or all (if occurs)) to view and display them there.
Pseudo-code:
errorFor( 'username', 'not_empty' ) => 'Username is required! Try again...';
How to define different error for each rule? I can’t find anything understandable for me in the docs…
You have:
So, first you should check if variables pass validation:
Then you should have user.php file in application/messages
To display errors: