Welcome Guest, Not a member yet? Register   Sign In
Form validation error messages?
#1

[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
#2

[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
#3

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

L8rs
#4

[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-gui...tingerrors
#5

[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.
#6

[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.
#7

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

Yeah sorry about that. Bit tense.

Pull request added.




Theme © iAndrew 2016 - Forum software by © MyBB