views:

240

answers:

1

I'm using Kohana validation library and I want to set up my own user friendly error messages. The problem is that I generate the form dynamically, so field names are not know during development.

Can a set up error messages for the different validation rules (required, digit, ...) regardless the field name? How?

Note: I'm using Kohana v2.3.4

+1  A: 

I know about this problem.

What I ended up doing, is something like this (though this does not know what type of error occurred, it worked for me in my situation).

Assume $errors are the errors returned from the validation library.

My view

<input type="text" id="input-something" name="something" />
<?php if (isset($errors['something']): ?>
<label for="input-something" class="error">Something didn't go right!</label>
<?php endif; ?>

Usually I would echo the $errors['something'] as the text node of the label element, but because they are defined dynamically, I just printed a general purpose error.

It's not a great solution, but you may be able to get away with it.

alex