Pages

Thursday, July 30, 2015

Cakephp 2.0-Validations not working

Many a times Our custom Validations do not work in cakephp due to very tiny small errors.Here is a piece of my research and development which might help you
 In the controller
       if (!empty($this->data))   
       {  
         $this->User->set($this->data);  
         if ($this->User->validates())   
         {  
           // it validated logic  
           echo "Yes we can proceed";  
         }   
         else   
         {  
           // didn't validate logic  
           $errors = $this->User->validationErrors;  
           pr($errors);  
         }  
       }  

See the line in Bold this must be done to get errors set

In the view
   <?php   
       if($this->Form->isFieldError('User.username'))  
       {  
         echo $this->Form->error('User.username', null, array('class' => 'message'));   
       }  
       ?>  
Now set the class to taste and you will get error message in view in desired color.

No comments:

Post a Comment