CodeIgniter Forums
Setting Validation Error Messages - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Setting Validation Error Messages (/showthread.php?tid=13208)



Setting Validation Error Messages - El Forum - 11-14-2008

[eluser]mradlmaier[/eluser]
Hi,
The User Guide states:

Quote:
Code:
$this->form_validation->set_message('rule', 'Error Message');

Where rule corresponds to the name of a particular rule, and Error Message is the text you would like displayed.

Either I am missing something in the User Guide, but what is the name of a rule?

The Guide also states:

Quote:
Code:
$this->form_validation->set_rules('email', 'Email', 'required');
The above function takes three parameters as input:

1. The field name - the exact name you've given the form field.
2. A "human" name for this field, which will be inserted into the error message. For example, if your field is named "user" you might give it a human name of "Username". Note: If you would like the field name to be stored in a language file, please see Translating Field Names.
3. The validation rules for this form field.

So, where is the name of this rule?

I need to know this to set error messages for a each form field, like "The email is required."

Thanks,
Michael


Setting Validation Error Messages - El Forum - 11-14-2008

[eluser]khuram[/eluser]
Hi Mike

I am a total nobody on CI. Can you please tell me something about my questions. Its here
http://ellislab.com/forums/viewthread/96974/.

I'll check the user guide for your problem in the meanwhile.
Much thanks.
I know its kind of queer but what the hell. i aint getting no where with ppl not replying me. Sad


Setting Validation Error Messages - El Forum - 11-14-2008

[eluser]eger[/eluser]
The rule in the example is "required". So you would set
Code:
$this->form_validation->set_message('required', 'Umm... %s is required buddy.');
to change the error message for the "required" rule to show "Umm... Email is required buddy." when the email field is empty.


Setting Validation Error Messages - El Forum - 11-14-2008

[eluser]khuram[/eluser]
Hey what about my problem please
I know it sounds offensive
but so does coming first time to a forum and not getting a reply
for argument's sake, I have tried to search the topic before posting. Sad

once again,

[a]http://ellislab.com/forums/viewthread/96974/[/a]


Setting Validation Error Messages - El Forum - 11-14-2008

[eluser]mradlmaier[/eluser]
Eger,

So, that way I specify one error message for ALL 'required' rules, with substitued human field names, right? But I cannot specify an error message per rule AND per field, right?

Michael


Setting Validation Error Messages - El Forum - 11-14-2008

[eluser]eger[/eluser]
[quote author="mradlmaier" date="1226712976"]Eger,

So, that way I specify one error message for ALL 'required' rules, with substitued human field names, right? But I cannot specify an error message per rule AND per field, right?

Michael[/quote]

I don't see a way to do that according to the docs. Maybe someone else might have a clever way to do this...


Setting Validation Error Messages - El Forum - 11-24-2008

[eluser]moodh[/eluser]
form_error('fieldname'); also returns true or false, so a simple if works if you want to write your own messages per field instead of per rule:

Code:
if(form_error('fieldname')) {
   echo "oh, you missed a bunny!";
}

edit, sorry for the old topic bump, but he asked for more ways =)