![]() |
Issue - Form_Validation > Setting Error Messages > set_rule() - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Issue - Form_Validation > Setting Error Messages > set_rule() (/showthread.php?tid=72847) |
Issue - Form_Validation > Setting Error Messages > set_rule() - Porto - 02-19-2019 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/libraries/form_validation.html#setting-error-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. RE: Issue - Form_Validation > Setting Error Messages > set_rule() - xenomorph1030 - 02-20-2019 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.'); RE: Issue - Form_Validation > Setting Error Messages > set_rule() - PaulD - 02-20-2019 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 RE: Issue - Form_Validation > Setting Error Messages > set_rule() - Porto - 02-25-2019 (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! Issue SOLVED 25.02.2019 - Form_Validation > Setting Error Messages > set_rule() - Porto - 02-25-2019 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! |