CodeIgniter Forums
Form validation error messages? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forum-22.html)
+--- Thread: Form validation error messages? (/thread-54121.html)



Form validation error messages? - El Forum - 08-23-2012

[eluser]RecoilUK[/eluser]
Hi guys

So I have this form, and the errors if any exist are displayed to the right of the input field.

Going along this design decision, I really don't need the name of the field in the message as it's obvious it relates to that field. But I do want to include the character limits in the min_length[] and max_length[] rules.

For instance ...

This field needs at least 3 characters.

I know how to show it with the name using the %s, but to get the number, you have to include the name.

So I want to change the way it works.

Instead of using a %s for each value, I want a %f for the field name and %n for the number, or some other way of getting to the second value without using the first.

But I cant find where this code executes.

Any idea's of where to look?

Thanks



Form validation error messages? - El Forum - 08-23-2012

[eluser]RecoilUK[/eluser]
Its ok, found out how to do it.

If anyone else is interested, you can just use this for the second value placeholder in your message...

Code:
$this->form_validation->set_message('min_length', 'This field must contain at least %2$s characters.');

And the number changes as you change the rule.

L8rs


Form validation error messages? - El Forum - 08-23-2012

[eluser]RecoilUK[/eluser]
Maybe that should be in the user_guide.

L8rs


Form validation error messages? - El Forum - 08-23-2012

[eluser]CroNiX[/eluser]
[quote author="RecoilUK" date="1345743434"]Maybe that should be in the user_guide.

L8rs[/quote]
Or maybe read closer? Smile
http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#settingerrors


Form validation error messages? - El Forum - 08-23-2012

[eluser]RecoilUK[/eluser]
Your point is?

The user_guide says nothing about accessing the second argument.

If you use this code ...
Code:
$this->form_validation->set_message('min_length', 'This field must contain at least %s characters.');

You get the name of field which is not what you want. So you have to use %s twice in the error message, and the whole point of my post was to not use the name in the message.

From my original question ...
Quote:I know how to show it with the name using the %s, but to get the number, you have to include the name.

Quote:Or maybe read closer?

Back at you.


Form validation error messages? - El Forum - 08-23-2012

[eluser]CroNiX[/eluser]
So much for no coffee.

Feel free to add it to the docs if you thing they are lacking, and issue a pull request on github. Most likely it would get included, otherwise it probably won't.


Form validation error messages? - El Forum - 08-23-2012

[eluser]RecoilUK[/eluser]
Quote:So much for no coffee.

Yeah sorry about that. Bit tense.

Pull request added.