Returns FALSE if the form element is not exactly the parameter value. Returns FALSE if the form element is longer than the parameter value. Returns FALSE if the form element is shorter than the parameter value. Note: This rule requires Query Builder to be
Returns FALSE if the form element is not unique to the table and field name in the Returns FALSE if the form element does not differ from the one in the parameter. Returns FALSE if the form element does not match the regular expression. Returns FALSE if the form element does not match the one in the parameter. Returns FALSE if the form element is empty. The following is a list of all the native rules that are available to Then it will be passed as the second argument of your callback method. Method name between square brackets, as in: callback_foo, Parameter in your callback method, just add it normally after the To invoke a callback just put the method name in a rule, with YouĬan see that the form field data was passed to your callback method Reload your form and submit it with the word “test” as the username. load -> helper ( array ( 'form', 'url' )) $this -> load -> library ( 'form_validation' ) $this -> form_validation -> set_rules ( 'username', 'Username', 'callback_username_check' ) $this -> form_validation -> set_rules ( 'password', 'Password', 'required' ) $this -> form_validation -> set_rules ( 'passconf', 'Password Confirmation', 'required' ) $this -> form_validation -> set_rules ( 'email', 'Email', 'required|is_unique' ) if ( $this -> form_validation -> run () = FALSE ) Form validation, while simple to create, is generally very messy Messages, various control structures are usually placed within the form Usually requires a significant amount of code, and to display error Prep the data for insertion in the database.Īlthough there is nothing terribly complex about the above process, it.Pre-format the data if needed (Does the data need to be trimmed? HTML.The username can’tīe someone else’s existing username, or perhaps even a reserved word. Minimum length, and not exceed a maximum length. Validated to contain only permitted characters. For example, if a username is submitted it must be
Verify that the data is of the correct type, and meets the correctĬriteria.This process continues until you have submitted a valid form.Item, the form is redisplayed containing your data along with an If you submitted something invalid, or perhaps missed a required.Before explaining CodeIgniter’s approach to data validation, let’s