Welcome Guest, Not a member yet? Register   Sign In
Change validation message per field per error
#1

[eluser]e-antz[/eluser]
Sorry if the title make you confuse..

But, here is what I want to ask
CI just offer validation message via language file and through changing it on the fly..
But, it will change whole validation message of an error type..

And I want like this
Every field has its own error message..
For example I have "name", and "age" field.
They both are required but each field will produce different "required" error message,
"name" field will produce "Hi, you must fill your name"
"age" field will produce "We need to know your age before we proceed this process"

I look into the core, but don't have idea how to change it.
For now, I extend form_validation library and add some code to make it happen.
But it will run the validation process twice before produce preferred error message.

So, how can I do this?


Note: sorry for my English :-)
#2

[eluser]smilie[/eluser]
Well, you could try with http://ellislab.com/codeigniter/user-gui...#callbacks

Basically, on every found error in the form, it executes a function in which you can set your own error (text).

Regards,
Smilie
#3

[eluser]e-antz[/eluser]
Hi similie,
Thanks for your reply..
Actually I know the callback method or set my own error message in language file,
But, this won't solve the problem - or actually idea - that I have..

FYI, I found this idea when I use symfony framework and I like how they handle error message..
I don't want make CI acts like symfony but it will be nice if I can do the similar thing in CI..
#4

[eluser]smilie[/eluser]
e-antz:
I do not understand what do you mean then?

If you use callback, in the callback function you can set error message.
In it, you can place any (language file) param you wish...

Cheers,
Smilie
#5

[eluser]e-antz[/eluser]
I'm so sorry, I make you confuse,
I'm not a native English speaker, so maybe I write with wrong grammar.. :-)

As I said in the first post, I want each of form field has its own error message whether it use CI validation method or my own callback..
So, I don't need to write callback to use "required" function just for getting new error message..
I hope you can understand it.. :cheese:
#6

[eluser]smilie[/eluser]
Take a look then at:

core/language/english/form_validation.php

In there are all of the form validation messages.

What you could do is change that file to your needs, or copy it to new language (with your needs).

Ofcourse, you can also extend it with new validation rules.

Cheers,
Smilie
#7

[eluser]e-antz[/eluser]
Hi smilie,
I'm looking at that now..
It seems to be the only way I can do with the validation..

But, actually this is not critical problem..
It just my idea..

Btw, thanks for your reply.. :cheese:




Theme © iAndrew 2016 - Forum software by © MyBB