Issue - Form_Validation > Setting Error Messages > set_rule() |
Hi Guys,
Could someone please give a Light what's going wrong here please? I try to set a custom error message for a particular field on some particular rule, but when i call the rule, i still see the native error messages from the file system/language/english/form_validation_lang.php. I've checked other Posts from another users, but i didn't find the correct answer for that. I try to do exactly what the documentation says, but till now it doesn't work. Documentation: https://www.codeigniter.com/userguide3/l...r-messages "If you need to set a custom error message for a particular field on some particular rule, use the set_rules() method:" Code: $this->form_validation->set_rules('field_name', 'Field Label', 'rule1|rule2|rule3', array('rule2' => 'Error Message on rule2 for this field_name')); This is my Post Method. Code: // CREATE NEW POST FORM And this is my view Form file Code: <!-- FORMNAME --> I thank you in Advance for any Help or Light.
What version of CodeIgniter are you running? I tried out your rule and I see the custom message in 3.1.10.
For the heck of it, have you tried overriding the whole form_validation with PHP Code: $this->form_validation->set_message('required', 'Test message.');
I agree with xenomorph1030 in the previous post. I too added your exact error message override to one of my form validation rules for a field and it gave your error message as expected.
PHP Code: $this->form_validation->set_rules('name', 'Name', 'trim|required|min_length[3]|max_length[100]', array('required' => 'O campo Título deve ter minimo 5 caracteres.')); Not much help sorry. Paul (02-20-2019, 10:39 AM)xenomorph1030 Wrote: What version of CodeIgniter are you running? I tried out your rule and I see the custom message in 3.1.10. I'm sorry, i'm trying again, and again and again and i don't get the message running! Another way to do the message to run is like that: PHP Code: $this->form_validation->set_rules('name', 'Name', 'trim|required|min_length[3]|max_length[40]', ['min_length' => 'O campo Nome deve ter pelo menos 3 caracteres de comprimento.']); But really, i still have difficulties to see what's going wrong with this message or what is missing in my configuration. PHP Code: $this->form_validation->set_rules('name', 'Name', 'trim|required|min_length[3]|max_length[100]', array('required' => 'O campo Título deve ter minimo 5 caracteres.')); And yes, i use as the documentation says the set_message() in a condition IF PHP Code: $this->form_validation->set_message('rule', 'Error Message'); What should i try again please? Thank you!
Dear xenomorph1030 & PaulD
I got it running! But i did a small change in the code. PHP Code: $this->form_validation->set_rules('name', 'Name', 'trim|required|min_length[5]|max_length[40]', array('min_length' => 'O campo Nome deve ter pelo menos 5 caracteres de comprimento.')); Thank you so much Guys! I appreciate that! |
Welcome Guest, Not a member yet? Register Sign In |