Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Data Validation in Cake PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 118
    Comment on it

    Data validation becomes an important part of any of the application. It helps to make it sure that the data input by the user is proper or not. Defining the validation rules in any application makes the form handling easier. Validation differs from field to field.

    In Cake PHP the defined section is for the model side of things.

    The very first step to make data validation is to create the validation rules in the Model. To use the validation in the model , we validate array in the Model , for example:

    class Form extends AppModel {
        public $validate = array();
    }
    

    In the above example, the $validate array is added to Form Model. The array do not contain any validation rule.
    Assuming that the Form table has login, password, email so the validation for these basic field will be like this :

    class Form extends AppModel {
        public $validate = array(
            'login' => 'alphaNumeric', // only leters and number will be accepted
            'email' => 'email', // valid email should be accpeted
            'born' => 'date'
        );
    }
    

    Defining validation rules enables automatic error message in cakephp when the input data is in incorrect format.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: