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

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 163
    Comment on it

    Validation in cakePHP is on the client side and on the server side.

    Client side validation is on the js file that is in the webroot folder.

    Server side validation is on the model which we are using.

    Client side validation is important as it do not save the data even if the client side validaton do not work.

    For client side validation

    class User extends AppModel {
     public $validate = array( 
    'login' => array(
     'alphaNumeric' => array(
     'rule' => 'alphaNumeric',
     'required' => true,
     'message' => 'Letters and numbers only'
     ), 
    between' => array(
     'rule' => array('
    lengthBetween', 5, 15
    ), 
    'message' => 'Between 5 to 15 characters'
     ) ), 
    'password' => array(
     'rule' => array('minLength', '8'),
     'message' => 
    'Minimum 8 characters long'
     ), 
    'email' => 'email',
     'born' => array(
     'rule' => 'date',
     'message' => 'Enter a valid date',
     'allowEmpty' => true 
    )
     ); }

    here we give first the field and then the rule that are to be applied on them.

    If there is an error we also display messag

 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: