Codeigniter Custom Form Error Messages
Contents |
here for a quick overview of the site Help Center Detailed answers to any codeigniter form validation error message questions you might have Meta Discuss the workings and policies set custom error message in codeigniter of this site About Us Learn more about Stack Overflow the company Business Learn more codeigniter set custom validation message 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 codeigniter file upload custom error messages Overflow is a 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
Codeigniter Error Messages Form_validation
$this->form_validation->set_message('is_unique[users.username]', 'The username is 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,15373065 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 doi
here for a quick overview of the site Help Center Detailed answers to
Codeigniter Validate Email
any questions you might have Meta Discuss the workings and codeigniter form validation error message not showing policies of this site About Us Learn more about Stack Overflow the company Business Learn codeigniter error message display 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 http://stackoverflow.com/questions/14460620/custom-error-message-using-codeigniter-form-validation 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 Custom form validation error message for Codeigniter 2 up vote 4 down vote favorite 1 I have a drop down named "business_id". Here comes the validation rule, user must select an option. $this->form_validation->set_rules('business_id', 'Business', 'greater_than[0]'); Problem being the error message says: The Business field must contain a number greater than 0. Not very intuitive! I want it to say "You must select a business". I tried: $this->form_validation->set_message('Business', 'You must select a business'); But CI complete ignores this. Does anyone have a solution for this? php codeigniter validation share|improve this question edited Apr 30 '11 at 3:42 Yi Jiang 35.6k11105121 asked Apr 30 '11 at 3:39 pigfox 3393925 add a comment| 11 Answers 11 active oldest votes up vote 2 down vote accepted Try not setting the value attribute on the default select... and then just using required for your form validation rule... $this->form_validation->set_rules('business_id', 'Business', 'required'); I suppose you could try editing the way that you're trying to set the message also... $this->form_val
that helps minimize the amount of code you'll write. Overview Form Validation Tutorial The Form The Success Page The Controller Setting Validation Rules Setting Validation Rules https://www.codeigniter.com/userguide2/libraries/form_validation.html Using an Array Cascading Rules Prepping Data Re-populating the Form Callbacks Setting Error Messages Changing the Error Delimiters Translating Field Names Showing Errors Individually Saving Sets of Validation Rules to a Config File Using Arrays as Field Names Rule Reference Prepping Reference Function Reference Helper Reference Overview Before explaining CodeIgniter's approach to data validation, let's describe the ideal scenario: error message A form is displayed. You fill it in and submit it. If you submitted something invalid, or perhaps missed a required item, the form is redisplayed containing your data along with an error message describing the problem. This process continues until you have submitted a valid form. On the receiving end, the script must: Check for required data. Verify codeigniter form validation that the data is of the correct type, and meets the correct criteria. For example, if a username is submitted it must be validated to contain only permitted characters. It must be of a minimum length, and not exceed a maximum length. The username can't be someone else's existing username, or perhaps even a reserved word. Etc. Sanitize the data for security. Pre-format the data if needed (Does the data need to be trimmed? HTML encoded? Etc.) Prep the data for insertion in the database. Although there is nothing terribly complex about the above process, it usually requires a significant amount of code, and to display error messages, various control structures are usually placed within the form HTML. Form validation, while simple to create, is generally very messy and tedious to implement. Form Validation Tutorial What follows is a "hands on" tutorial for implementing CodeIgniters Form Validation. In order to implement form validation you'll need three things: A View file containing a form. A View file containing a "success" message to be displayed upon successful su