Welcome Guest, Not a member yet? Register   Sign In
Set validation message for a specific field?
#1

[eluser]Shpigford[/eluser]
Is there a way to do validation->set_message and change the name of the field?

I have an input named "title" and if "title" is empty it says "The title field is required"...what I would like that message to say is "The site name field is required."

How can I do that?
#2

[eluser]cinewbie81[/eluser]
The following will works

Code:
$rules['title'] = "required";
$this->validation->set_rules($rules);

$fields['title'] = 'Site Name';
$this->validation->set_fields($fields);
#3

[eluser]Shpigford[/eluser]
Doesn't that change the actual contents of the input? I just want to change what the error message says.
#4

[eluser]cinewbie81[/eluser]
It will change the error message
#5

[eluser]daniel.affonso[/eluser]
It was not working for me too.

I was using this before:
Code:
$this->validation->set_fields($this->fields);

I change for this and now works:
Code:
$fields = $this->fields;
$this->validation->set_fields($fields);

@Shpigford: I hope this is help you.

ps.: I think here we are free to change and share knowledge and not to impose truths...
#6

[eluser]cinewbie81[/eluser]
Not sure how do u mean "not to impose truths" ...
but my code definitely works .. at least it's works for me ..
have a look at the help file
#7

[eluser]daniel.affonso[/eluser]
Hi,

Quote:at least it’s works for me

That's the point...

You are RIGHT, but the user guide examples not works for all situations.

And, finally, I ask excuses for anything.

Thanks.
#8

[eluser]dootzky[/eluser]
i think this is the key explanation from the help file:

Quote:The array keys are the actual names of the form fields, the value represents the full name that you want shown in the error message.

full link: http://ellislab.com/codeigniter/user-gui...ation.html
search the headline: "Re-populating the form"

i think you'll get it then. Smile
i got mixed up just like Shpigford on the first glance, but this forum and totally sexy documentation helped me out.
great stuff.

cheers, CI rulzs.
d.
#9

[eluser]aataqwa[/eluser]
your change file system/language/english/validation_lang.php

sory, my english bad.
#10

[eluser]Bramme[/eluser]
Or you just go with the first reply, which is exactly what the topic starter wanted... Why the hell do you make things so complicated?




Theme © iAndrew 2016 - Forum software by © MyBB