How To Set Custom Error Message In Codeigniter
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and codeigniter error message display policies of this site About Us Learn more about Stack Overflow the
Codeigniter Form Validation Error Message Not Showing
company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags how to change validation message in codeigniter Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only codeigniter form validation custom rules takes a minute: Sign up How to set custom error message with form_validation And CodeIgniter up vote 3 down vote favorite i am newbie in CodeIgniter...and i am trying to do form validation for array input... the array name is pages[]. and i wrote: $this->form_validation->set_rules('pages[]','','required'); if i use that: $this->form_validation->set_message('required', 'you not selected pages.'); it will not change the other "required"
Unable To Access An Error Message Corresponding To Your Field Name.
validation input params? So how can i set error message only for one validation? php codeigniter share|improve this question asked Sep 5 '10 at 15:23 CaTz 1203418 add a comment| 1 Answer 1 active oldest votes up vote 2 down vote accepted It doesn't work like you stated, you should read this section of the user guide more carefully. I'm not sure I can explain better, but the first field of the set_message method doesn't refer to the type of validation but to the callback function's name, that's the function which is doing the custom validation work. What you need to do is define your callback function (the guide has a good example), in which you iterate through your array's elements and count what's checked. If at the end of the iteration the counter is 0 you set your error message. Hope this helps. share|improve this answer answered Sep 6 '10 at 6:46 kitsched 1,22311233 although codeigniter 2 should have a function for setting up a custom message, there is a workaround for this problem here http://stackoverflow.com/questions/9108718/how-can-i-setup-custom-error-messages-for-each-form-field-in-codeigniter –m
here for a quick overview of the site Help Center Detailed answers to any questions codeigniter 3 form validation you might have Meta Discuss the workings and policies of show validation error message in codeigniter this site About Us Learn more about Stack Overflow the company Business Learn more about hiring
Codeigniter Form Validation Example
developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a http://stackoverflow.com/questions/3646553/how-to-set-custom-error-message-with-form-validation-and-codeigniter community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Custom error message using CodeIgniter Form Validation up vote 4 down vote favorite 2 I want to make some custom error messages in my CodeIgniter forms. I've tried using $this->form_validation->set_message('is_unique[users.username]', 'The username is http://stackoverflow.com/questions/14460620/custom-error-message-using-codeigniter-form-validation already taken'); However I can't get it working. Editing the form_validation_lang.php file is not good enough, as is_unique will be The username is already taken for usernames, and The e-mail is already registered for mails. How can I make this custom error message? Here's a snippet from my code: $this->form_validation->set_message('is_unique[users.username]', 'The username is already taken'); // Check if username has changed if ($this->input->post('username') !== $user->username) { $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]|max_length[20]|is_unique[users.username]'); } php forms codeigniter validation share|improve this question asked Jan 22 '13 at 14:15 Patrick Reck 4,18873065 1 check out the form validation example on the codeigniter documentation site.. ellislab.com/codeigniter/user-guide/libraries/… –MrFoh Jan 22 '13 at 14:26 The code example I posted is identical to the docs: $this->form_validation->set_message('required', 'Your custom message here'); –Patrick Reck Jan 22 '13 at 15:47 add a comment| 4 Answers 4 active oldest votes up vote 10 down vote accepted Right way of doing this is by passing a string format $this->form_validation->set_mess
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the http://stackoverflow.com/questions/12473124/form-validation-custom-message-in-codeigniter company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Form validation custom message in codeigniter? up vote 2 down vote favorite 1 In codeigniter I have used codeigniter form error message validation library in many controller, ex: - $this->form_validation->set_rules('rank', 'Rank', 'required'); If form validation failed, Then it displays "The Rank field is required." Here I want to display custom message,One method I can follow is $this->form_validation->set_message('required', '%s can not be blank'); If I using this method then I need to repeat this code in every controller wherever I am using "required" form validation method My question is there is any method to declare this custom message in codeigniter message in configure file and automatically use this custom message whenever I using form validation rule "required"? php codeigniter validation share|improve this question edited Sep 18 '12 at 8:32 Amr 1,65921730 asked Sep 18 '12 at 8:30 shihabudheen 243511 add a comment| 3 Answers 3 active oldest votes up vote 4 down vote accepted If you want to permanently over-ride the error message just hard code it into the form_validation_lang.php file. (Located at system/language/english) It you want the choice the extend the form_validation class adding your custom required function and add the appropriate error message in the lang file. For example; class MY_Form_validation { public function custom_required($str) { if ( ! is_array($str)) { return (trim($str) == '') ? FALSE : TRUE; } else { return ( ! empty($str)); } } } Then in the lang file; $lang['custom_required'] = "%s can not be blank."; share|improve this answer edited Sep 18 '12 at 8:42 answered Sep 18 '12 at 8:37 Rooneyl 4,73632751 Thank you ,Now working well –shihabudheen Sep 18 '12 at 8:47 add a comment| up vote 1 down vote From the CI docs themselves: "All of the native error messages are located in the following language file: language/english/form_validation_lang.php To set your own custom message you can either edit that file, or use the following function: $this->form_valida