Now, my question is, how can I easily validate that all my required inputs are there?
I know I can just use the `empty()` function from PHP, but to do that for 4 different inputs can get dirty (especially if I do it for a longer period of time with more and more inputs across the site)
// set the validator instance $v = Validation::forge(); // Set up our required validation rules $v->add('name', '')->add_rule('required'); $v->add('email','')->add_rule('required'); $v->add('subject','')->add_rule('required'); $v->add('message','')->add_rule('required');
and it seems to work just fine (I will add constraints later), but when I do not fill in one of the things, I get greeted by a huge array (duh, I use print_r()).
How can I get just the invalid forms?
Also, while I'm at it, how can I link it to the form itself (so I can easily display a message)
Some have more code to include the error message in the HTML, so it appears near the field, pops up with you enter it, etc. But that is front-end stuff, outside the scope of the framework.
Fieldset forms have an "error_msg" and an "error_class" variable in the form template. These can be used if you use the fieldset for validation, instead of a separate validation object.
error() returns an assoc array with field names => validation error objects. The object has a get_message() method to fetch the error message, with or without formatting (either passed of from the configuration). You can also echo the object directly, which will output the message.